将嵌套列表拆分为两个列表 [英] Splitting a nested list into two lists

查看:40
本文介绍了将嵌套列表拆分为两个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的嵌套列表:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆