How do I merge lists with same length?

Hello everyone,
I have been looking for a solution to my problem for a few days without an answer.
I have 2 lists of the same length that I would like to merge as below.
How to do? thanks in advance

First list : ["0h", "1h", "2h", "3h", "4h", "5h", "6h", "7h", "8h", "9h", "10h", "11h", "12h", "13h", "14h", "15h", "16h", "17h", "18h", "19h", "20h", "21h", "22h", "23h"]

Seconde list: [["309", "726"], ["783", "694"], ["9", "844"], ["923", "771"], ["42", "378"], ["705", "730"], ["224", "269"], ["673", "477"], ["624", "236"], ["177", "830"], ["767", "935"], ["107", "182"], ["99", "490"], ["193", "896"], ["99", "44"], ["680", "528"], ["412", "603"], ["751", "584"], ["552", "584"], ["512", "82"], ["720", "997"], ["354", "972"], ["346", "887"], ["455", "413"], ["217", "125"]]

Final list that i want : [["0h", "309", "726"], ["1h", "783", "694"], [...] , ["23h", "217", "125"]]

Here is one way to do it, creates a new list from the other two lists

Output:

[[1, "a", "a1"], [2, "b", "b2"], [3, "c", "c2"]]
3 Likes

And another approach

3 Likes

Beware of modifying the input lists directly, as in @dora_paz's approach.
It is more conservative to copy the input first, as in @TIMAI2's approach.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.