如何替换/卸下方括号& python列表中的bouble引号
我需要从列表列表中删除方括号(列表包含子列表)
list = [["'deliver","'ordered","'delivery","'delivering","'brought"],["'deliver","'offering","'providing","'delivers","'orders"]]
示例输出
list = 'deliver','ordered','delivery','delivering','brought'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
播放列表理解,这就是它的
目的
Play with list comprehension, thats what its there for
Or you could just list slice after you edit using list comprehension
存在嵌套列表中,则将删除双打
如果按照正常方式
set will remove doublicates if exist in your nested list
as normal way
您是否想要重复的?从这个问题中不清楚。
如果您不在乎具有重复项,请使用列表理解:
如果您不想要重复项,请使用集合理解并将其转换回列表:
在这两个示例中,我们使用使用每个字符串的内部单引号剥离方法,一旦将其删除,Python会自动将双引号转换为单引号。但是,有双引号或单引号无关紧要,结果列表中的项目仍然具有字符串。在此处提到的情况下,什么样的引号很重要:
https://www.geeksforgeeks.orgs.org/single-and-and-double-quotes-python/#:~:~: 2c%20 double%20 Quotes%20ARE%20使用,1%20 type%20over%20 the%20other 。
Do you want duplicates or not? It's unclear from the question.
If you don't care about having duplicates, use a list comprehension:
If you don't want duplicates, then use a set comprehension and convert it back to a list:
In both examples, we remove the inner single quotation from each string using the strip method, and once it is removed, python automatically converts the double quotes to single quotes. However, the fact that there are double quotes or single quotes doesn't matter, the items in the resulting lists still have type string. What kind of quotations only matters in cases mentioned here:
https://www.geeksforgeeks.org/single-and-double-quotes-python/#:~:text=Generally%2C%20double%20quotes%20are%20used,one%20type%20over%20the%20other.