I have a list of tuples like:
tuple_list = [ (0,1,2), (3,4,5), (6,7,8) ]
I need to create a list where each tuple is converted into a list with other static items added e.g.:
new_list = [ [var1, var2, unpack(t)] for t in tuple_list ]
How would I accomplish this in python?
If your tuple is not too long, you can do:
[var1, var2, k, v, r for (k, v, r) in youList]
otherwise, write a function:
def myPack(*arg):
return list(arg)
[myPack(var1, var2, *I) for I in youList]
new_list = [ [var1, var2] + list(t) for t in tuple_list ]
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