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的更多相关文章

  1. 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 ...

  2. 如何将List<string>转化为string

    Convert List, string. A List can be converted to a string. This is possible with the ToArray method ...

  3. 自然语言16.1_Python自然语言处理学习笔记之信息提取步骤&分块(chunking)

    QQ:231469242 欢迎喜欢nltk朋友交流 http://www.cnblogs.com/undercurrent/p/4754944.html 一.信息提取模型 信息提取的步骤共分为五步,原 ...

  4. Python 系列:1 - Tuples and Sequences

    5.3 Tuples and Sequences We saw that lists and strings have many common properties, e.g., indexing a ...

  5. Device Tree Usage( DTS文件语法)

    http://elinux.org/Device_Tree_Usage Device Tree Usage     Top Device Tree page This page walks throu ...

  6. Python数据结构与算法--数据类型

    从数据类型开始 Python支持面向对象的编程范式,这意味着Python把数据看成解决问题的关键. 在Python中,类似其他的面向对象的编程语言, 我们定义一个类,用来描述数据是什么 (状态) 和数 ...

  7. python中的yield

    在理解yield之前,要首先明白什么是generator,在理解generator之前首先要理解可迭代的概念. 可迭代(iterables)在你创建一个list的时候,可以逐个读取其中的元素,该逐个读 ...

  8. Think Python - Chapter 18 - Inheritance

    In this chapter I present classes to represent playing cards, decks of cards, and poker hands.If you ...

  9. Class attributes

    In order to print Card objects in a way that people can easily read, we need a mapping from the inte ...

随机推荐

  1. Dalvik虚拟机垃圾收集(GC)过程分析

    前面我们分析了Dalvik虚拟机堆的创建过程,以及Java对象在堆上的分配过程. 这些知识都是理解Dalvik虚拟机垃圾收集过程的基础.垃圾收集是一个复杂的过程,它要将那些不再被引用的对象进行回收.一 ...

  2. nmq 提交到 npm

    安装npm install nmq 源码:https://github.com/ronwe/nmq 此版本提供 pub/sub , 优化 pull

  3. QMutex“A mutex must be unlocked in the same thread that locked it”解决(在run里创建对象是不二法宝)

    多线程时出现如下警告信息: A mutex must be unlocked in the same thread that locked it: 原因可能有二: 1.创建QMutex不在当前线程: ...

  4. zzulioj--1633--Happy Thanksgiving Day - Hateable Name(字符串筛选)

     1633: Happy Thanksgiving Day - Hateable Name Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 75   ...

  5. [jzoj 6086] [GDOI2019模拟2019.3.26] 动态半平面交 解题报告 (set+线段树)

    题目链接: https://jzoj.net/senior/#main/show/6086 题目: 题解: 一群数字的最小公倍数就是对它们质因数集合中的每个质因数的指数取$max$然后相乘 这样的子树 ...

  6. HD-ACM算法专攻系列(13)——How Many Fibs?

    问题描述: 源码: import java.math.BigInteger; import java.util.*; public class Main { //主函数 public static v ...

  7. 51nod 1158 全是1的最大子矩阵(单调栈 ,o(n*m))

    前置问题:51nod 1102 面积最大的矩形 附上链接: 51nod 1102 面积最大的矩形 这题的题解博客 需要了解的知识:单调栈,在前置问题中已经讲解. 解题思路 对每行求左边连续1的个数,得 ...

  8. Caffe 激励层(Activation)分析

    Caffe_Activation 一般来说,激励层的输入输出尺寸一致,为非线性函数,完成非线性映射,从而能够拟合更为复杂的函数表达式激励层都派生于NeuronLayer: class XXXlayer ...

  9. A. Amr and Music

    解题思路:给出n种乐器学习所需要的时间,以及总共的天数, 问最多能够学多少门乐器,并且输出这几门乐器在原序列中的序号(不唯一) 按照升序排序,为了学到最多的乐器,肯定要选择花费时间最少的来学习 然后用 ...

  10. Set集合[HashSet,TreeSet,LinkedHashSet],Map集合[HashMap,HashTable,TreeMap]

    ------------ Set ------------------- 有序: 根据添加元素顺序判定, 如果输出的结果和添加元素顺序是一样 无序: 根据添加元素顺序判定,如果输出的结果和添加元素的顺 ...