python - 如何将带有逗号分隔项的字符串转换为 Python 中的列表?

标签 python string list

如何将字符串转换为列表?

假设字符串类似于 text = "a,b,c"。转换后,text == ['a', 'b', 'c'] 并希望 text[0] == 'a', text [1] == 'b'?

最佳答案

像这样:

>>> text = 'a,b,c'
>>> text = text.split(',')
>>> text
[ 'a', 'b', 'c' ]

关于python - 如何将带有逗号分隔项的字符串转换为 Python 中的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5387208/

相关文章:

python - 在spark(python)中划分两个rdds的值

css - 无法让我的元素符号列表正确显示

python - 有效地确定超出后续数字范围的数字是否在有序列表中。 (在 Python 中)

string - 在SQL Server 2005中的表列上进行修剪

linux - 如何计算字符串中的特定字符 - CSH

python - 计算字符串中的连续字符

java - 如何对列表中两个不同类的字段进行排序?

python - 在 Python 中使用 enumerate() 将索引旋转回 `for` 循环中的第一个元素的更好方法

python - 访问/分段 numpy 重新数组中的列

python - 查找区间索引的有效方法