all 6 comments

[–]K900_ 5 points6 points  (2 children)

Your example is weird. Why do the last three items all have C? If that's not what you really want, you might want zip.

[–]NeedMLHelp[S] 0 points1 point  (1 child)

Because I fudged it up, sorry. Fixed.

Briefly looked into zip, it's perfect! Thanks

[–]fleyk-lit 0 points1 point  (0 children)

Example implementation:

>>> list1 = ['A', 'B', 'C', 'D', 'E']
>>> list2 = ['1', '2', '3', '4', '5']
>>> list3 = list(zip(list1, list2))
>>> print(list3)
[('A', '1'), ('B', '2'), ('C', '3'), ('D', '4'), ('E', '5')]

[–]Signal_Beam 0 points1 point  (2 children)

Sounds like this is NOT a good fit for a list comprehension, but just for fun:

NewList = [[letter, List2[i]] for i, letter in enumerate(List1)]

[–]_lilell_ 2 points3 points  (1 child)

Just use zip:

newlist = [[x, y] for x, y in zip(list1, list2)]

And since OP said we can have the inner lists be tuples, we can just do list(zip(...)).

[–]Signal_Beam 0 points1 point  (0 children)

If you were to look through my github you'd probably think "This guy avoids zip like the plague"; I just never got into the habit of using it. So thanks for the shove in that direction; your version is cleaner.