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. WAP 图片 lazyload

    原理是根据屏幕上的坐标找到需要做 lazyload 的区域 1,先监听 scroll 事件 ,scrolling_lt window.addEventListener('scroll', functi ...

  2. bzoj4519: [Cqoi2016]不同的最小割(分治最小割)

    4519: [Cqoi2016]不同的最小割 题目:传送门 题解: 同BZOJ 2229 基本一样的题目啊,就最后用set记录一下就ok 代码: #include<cstdio> #inc ...

  3. [JZOJ 5906] [NOIP2018模拟10.15] 传送门 解题报告(树形DP)

    题目链接: https://jzoj.net/senior/#contest/show/2528/2 题目: 8102年,Normalgod在GLaDOS的帮助下,研制出了传送枪.但GLaDOS想把传 ...

  4. HD-ACM算法专攻系列(11)——Exponentiation

    问题描述: 源码: 考察对大数的计算,需要注意去除前导0与后导0. import java.math.BigDecimal; import java.util.*; public class Main ...

  5. C#调用GPG命令进行加密解密文件操作

    public void GPG() { string password = "1234567890"; System.Diagnostics.ProcessStartInfo ps ...

  6. java.lang.NoClassDefFoundError: org/springframework/dao/support/PersistenceE解决方法

    笔者是使用spring4.0时,报的错误: 原因是没有引入spring-tx-4.0.0.RELEASE.jar包,將spring-tx-4.0.0.RELEASE.jar添加到build path中 ...

  7. 51nod 1435 位数阶乘 (手动计算)

    题目: 1435 位数阶乘 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 X是一个n位数的正整数 (x=a0a1...an−1) ...

  8. sass的用法小结(四)进阶篇

    Sass 的数据类型 Sass 既然有了类似编程语言的功能,自然也就有了简单的数据类型.这里简单的介绍一些 Sass 中的数据类型,因为在后面的讨论中要用到有关的内容. Sass 中主要有六种数据类型 ...

  9. cuDNN编写卷积实例

    转载至http://www.goldsborough.me/cuda/ml/cudnn/c++/2017/10/01/14-37-23-convolutions_with_cudnn/ Convolu ...

  10. yii2.0 利用Excel类做导入导出

    1.在 common 目录下 创建一个 components 将 Classes目录(改名为PHPExcel)和PHPExcel.php 放在新创建的目录下.再在 components 下创建一个Co ...