Ad

Data Handling With Lists

My problem is related to handling data from multiple lists. Consider I have two lists.

a = ['a','b','c']
b = ['d','e','f','g','h']

I want to create a nested list which will add all the elements of one list (list a) into another (list b) without altering any elements in the second list (list b).

So, the output would look like:

output = [['a','d','e','f','g','h'], ['b','d','e','f','g','h'],['c','d','e','f','g','h']]

Can anyone say an efficient way to achieve this output. Thank you in advance.

Ad

Answer

This list comprehension seems to do the job:

output = [list(item) + b for item in a]
Ad
source: stackoverflow.com
Ad