python输入逗号分隔_Python实现按逗号分隔列表的方法

Python实现按逗号分隔列表的方法

方法一:

def commaSpiltList(self, listData):

listData = list(listData)

strs = str(listData[0])

for letter in range(1, len(listData) - 1):

strs = strs + ',' + str(listData[letter])

strs += ',' + str(listData[len(listData) - 1])

print(strs)

方法二:

#!/usr/bin/python

# -*- coding: UTF-8 -*-

L = [1,2,3,4,5]

s1 = ','.join(str(n) for n in L)

print s1

注意:字符串中替换字符的方法

s1 = ','.join(str(n) for n in listData)

以上这篇Python实现按逗号分隔列表的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

时间: 2018-10-20

问题 给出一段话,由短句组成,短句之间可能被任意标点符号隔开.想要提取所有的短句. 解决 使用 re.split 函数,用正则式匹配的方法,一次性分隔所有短句. import re pattern = r',|\.|/|;|\'|`|\[|\]|<|>|\?|:|"|\{|\}|\~|!|@|#|\$|%|\^|&|\(|\)|-|=|\_|\+|,|.|.|:|'|'

你可能感兴趣的:(python输入逗号分隔)