简体   繁体   English

Python 垂直阵列切片

[英]Python Vertical Array Slicing

Can anyone show me how to slice the structure below:谁能告诉我如何分割下面的结构:

[[1, A], [2, B], [3,C]]

Into two separate lists:分成两个单独的列表:

[1, 2, 3]
[A, B, C]

I can obviously do this using code, but wondered if Python was able to do it natively?我显然可以使用代码做到这一点,但想知道 Python 是否能够在本地做到这一点?

my_list = [[1, A], [2, B], [3, C]]
a, b = zip(*my_list)

Note that a and b will end up being tuples.请注意, ab最终将成为元组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM