简体   繁体   中英

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?

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

Note that a and b will end up being tuples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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