As you know zip() takes sequences as parameters and returns a list of tuples of elements mapped between those sequences. My question is : what if i have an undefined number of sequences?
lets say i have:
index=range(0,5)
field=['name','surname','age','gender','location']
data1=['john','nash','88','m','konya']
data2=['david','davidoff','100','m','istanbul']
if i use zip like below:
zip(index,field,data1,data2)
it works perfect, however my data is not limited to data1 and data2. I may have up to 10 records for each individual. I tried to append datai`s to another data[] array, however zip did not consider this as seperate sequences.
data=[]
data.append(data1)
data.append(data2)
zip(index,field,data)
gives no useful data as expected.
Appreciate any help for this.
Argument list unpacking:
to_zip = [index, field, data1, data2]
zip(*to_zip)
Or:
to_zip = [data1, data2]
zip(index, field, *to_zip)
Or whatever combination you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With