将嵌套列表分为两个列表 [英] Splitting a nested list into two lists
本文介绍了将嵌套列表分为两个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的嵌套列表:
I have a nested list like this:
my_list = [[1320120000000, 48596281], [1320206400000, 48596281], [1320292800000, 50447908]]
我想将其拆分为如下所示的内容:
I would like to split it into something that looks like this:
my_list1 = [48596281, 48596281, 50447908]
my_list2 = [1320120000000, 1320206400000, 1320292800000]
我知道这很简单,但是我无法使其正常工作.任何帮助将不胜感激.
I know that this is fairly simple, but I haven't been able to get it to work. Any help would be much appreciated.
推荐答案
这是内置函数 zip
用于.
This is what the builtin function zip
is for.
my_list2, my_list1 = zip(*my_list)
如果您想要列表而不是元组,则可以
If you want lists instead of tuples, you can do
my_list2, my_list1 = map(list, zip(*my_list))
这篇关于将嵌套列表分为两个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文