This is probably a beginners question but I don’t know how to search for an answer (because I cannot “name” the question)
I have 2 lists or a tuple of 2 lists
xxx = ["time1", "time2", "time3"]
yyy = ["value1", "value2", "value3"]
zzz=(xxx,yyy)
now I would like to create a list/tuple for every entry
result should be
[['time1', 'value1'], ['time2', 'value2'], ['time3', 'value3']]
I’m able to do this with a for loop (and zip) but is there no “nicer” solution?
Here is a similar question but I’m not able to use the resolution given there for my probelms
Use the builtin
zipfunction:Of course, this creates a list of tuples (or an iterable of tuples in python3.x). If you really want a list of lists:
or
If you’re using python3.x and you want to make sure that
zzzis a list, the list comprehsion solution will work, or you can construct a list from the iterable thatzipproduces: