简体   繁体   中英

How to manipulate an array in python?

I have an array like:

A=[[1,2,3,4,5,6,7,8,],[2,5,7,5,3,6,89,2],[22,44,55,77,88,34,44,66]]

I need them like:

C=[1,2,22] d=[2,5,44] e=[3,7,55]........ j=[8,2,66]

how to do it in python kindly help.

You can do this with zip:

[[a,b,c] for a,b,c in zip(*A)]

You can use zip without the need for writing the craziness you are talking about.

[list(i) for i in zip(*A)]

Likewise

name='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for n,i in enumerate(zip(*Arr)):
    globals() [ str(name[n]) ]=i

Output

print(A) #[1,2,22]

print(B)  #[2,5,44]
...

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