Lists and strings
A string is a sequence of characters and a list is a sequence of values, but a list of characters is not the same as a string. To convert from a string to a list of characters, you can use the list function:

list breaks a string into individual letters. If you want to break a string into words, you can use split method:

An optional argument called a delimiter specifies which characters to use as word boundaries. The following example uses ‘, ‘ ( a comma followed by a space) as the delimiter:

join is the inverse of split. It takes a list of strings and concatenates the elements. join is a string method, so you have to invoke it on the delimiter and pass the list as a parameter:

In this case, delimiter is a space character, so join puts a space between words. to concatenate strings without spaces, you can use the empty string, ‘’ as delimiter.
from Thinking in Python
Lists and strings的更多相关文章
- Think Python - Chapter 10 - Lists
10.1 A list is a sequenceLike a string, a list is a sequence of values. In a string, the values are ...
- 如何将List<string>转化为string
Convert List, string. A List can be converted to a string. This is possible with the ToArray method ...
- 自然语言16.1_Python自然语言处理学习笔记之信息提取步骤&分块(chunking)
QQ:231469242 欢迎喜欢nltk朋友交流 http://www.cnblogs.com/undercurrent/p/4754944.html 一.信息提取模型 信息提取的步骤共分为五步,原 ...
- Python 系列:1 - Tuples and Sequences
5.3 Tuples and Sequences We saw that lists and strings have many common properties, e.g., indexing a ...
- Device Tree Usage( DTS文件语法)
http://elinux.org/Device_Tree_Usage Device Tree Usage Top Device Tree page This page walks throu ...
- Python数据结构与算法--数据类型
从数据类型开始 Python支持面向对象的编程范式,这意味着Python把数据看成解决问题的关键. 在Python中,类似其他的面向对象的编程语言, 我们定义一个类,用来描述数据是什么 (状态) 和数 ...
- python中的yield
在理解yield之前,要首先明白什么是generator,在理解generator之前首先要理解可迭代的概念. 可迭代(iterables)在你创建一个list的时候,可以逐个读取其中的元素,该逐个读 ...
- Think Python - Chapter 18 - Inheritance
In this chapter I present classes to represent playing cards, decks of cards, and poker hands.If you ...
- Class attributes
In order to print Card objects in a way that people can easily read, we need a mapping from the inte ...
随机推荐
- Webstorm快捷键整理
Webstorm快捷键整理 F2/Shift F2 下一个/上一个高亮错误 Ctrl+Shift+BackSpace 回到刚刚编辑的地方 Alt+Insert 新建文件,还有其他功能 Ctrl+D ...
- Vitual Router in The Cloud
VyOS and ESXi,VyOS Configuration The next step is to configure both VyOS routers. Before we do, we s ...
- HDU 2841 Visible Trees(容斥定理)
Visible Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- bzoj1218: [HNOI2003]激光炸弹(DP二维前缀和)
1218: [HNOI2003]激光炸弹 题目:传送门 题解: 一道经典题目啊... 为了更好的操作...把整个坐标系向右上角移动,从(1,1)开始 那么f[i][j]统计一下以(i,j)作为右上角, ...
- iOS学习必须了解的七大手势
文章只要你有一点点基础应该就可以看的懂,文章只为学习交流 #import "ViewController.h" @interface ViewController () @prop ...
- ORACLE 11GR2 RAC的网络规划解析
在ORACLE 11gR2中,安装RAC发生了显著变化.在10g以及11gR1的时代,安装RAC的步骤是先安装CRS,再安装DB,而到了11gR2的时代,crs与asm被集成在一起,合称为GRID,必 ...
- correct ways to define variables in python
http://stackoverflow.com/questions/9056957/correct-way-to-define-class-variables-in-python later say ...
- Charles抓取微信小程序数据 以及 其它应用网站数据
为了抓取小程序数据所以使用Charles来抓取,下面介绍下使用方法(mac环境下使用).使用Charles可以非常方便的抓取Http/Https请求.官方dmg下载地址:点击此处下载 Charles抓 ...
- HDU 1285 确定比赛名次【拓扑排序】
题意:中文的题目-----这道题让我终于明白了那个break的作用---因为题目中有这一句“符合条件的排名可能不是唯一的,此时要求输出时编号小的队伍在前”@_@ #include<iostrea ...
- 51nod 1110 距离之和最小V3
X轴上有N个点,每个点除了包括一个位置数据X[i],还包括一个权值W[i].点P到点P[i]的带权距离 = 实际距离 * P[i]的权值.求X轴上一点使它到这N个点的带权距离之和最小,输出这个最小的带 ...