我有一个列表:
lst = ['words in a list']
我希望将字符串中的每个单词拆分成它们自己单独的索引。因此,例如,它看起来像这样:
lst = ['words','in','a','list']
我想知道这是否可能?我最初以为这只是一个带有循环的简单 lst.split(),但看起来这会引发错误。
感谢您的帮助!
最佳答案
使用这个:
print(lst[0].split())
如果列表有更多元素:
print([x for i in lst for x in i.split()])
关于python - 将单个索引列表拆分为多个列表索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54545646/