python - 将单个索引列表拆分为多个列表索引?
问题描述
我有一个清单:
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()])
推荐阅读
- listview - SwiftUI 如果列表视图上有太多项目,为什么我的列表视图上的按钮会停止工作?
- html - 嵌套 Div 容器打破 flex wrap
- python - Python - 相同的字母但不同的字体/ascii 代码/编码?
- javascript - 如何一次将每个用户的孩子添加到另一个孩子火力基地下?
- arrays - 如何执行预定义的异步函数调用
- decorator - 更改 @track 值时 LWC 不更新视图
- nginx - Nginx 反向代理 HTTP2
- c - OpenSSL/OCSP 装订;如何在传递给 SSL_CTX_set_tlsext_status_cb(...) 的回调中访问 SSLContext?
- git - Visual Studio 2019 中的 SSH Bitbucket 克隆不起作用
- .net-core - 如何在 .NET Core 3 中不将代理与 RestSharp 一起使用