简体   繁体   中英

creating list of tuples from multiple vectors and constants

I have the following data:

m = 12
d = 10
ar1 = np.array([1,4,5,6])
type = [p,q,r,s] #same size as ar1

I want to create the following list of tuples:

[(12,10,1,p), (12,10,4,q), (12,10,5,r), (12,10,6,s)]

I tried using zip in various forms but I am not able to get the syntax right

使用zip和列表理解:

[(m,d,x,y) for x,y in zip(ar1,type)]

这应该可以解决问题:

the_tuple = [ (m, d, n[0], n[1]) for n in zip(ar1,type) ]

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