删除双重列表的外部列表 [英] Remove the outer list of a double list
本文介绍了删除双重列表的外部列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个包含以下内容的列表:
Let's say i have a list that consist of:
[['a','b','c','d']]
是否有一种简单的方法可以删除外部列表,以便输出为
Is there an easy way to remove the outer list so the output would be
['a','b','c','d']
我想到了pop之类的东西,但是删除了元素,我只想删除外部列表.
I figured something like pop, but that remove the element, and i just want to remove the outer list.
我知道我可以遍历双重列表并将元素添加到新列表中,并且可以解决问题,但我对该解决方案不满意,我希望使用更干净的代码来使之更平滑.
I know i could iterate over the double list and append the elements to a new list, and the problem would be solved, but im not happy with that solution, i want a smoother one with cleaner code.
推荐答案
您可以使用拆包:
[new_list] = [['a','b','c','d']]
print(new_list)
输出:
['a','b','c','d']
这篇关于删除双重列表的外部列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文