Home > Net >  How to Concrete a 2D Python List to 1D
How to Concrete a 2D Python List to 1D

Time:11-15

A given 2d list say [['D', 'S'], ['A', 'M'], ['I', 'N'], ['C', 'F'], ['E', 'T']] is needed to concrete to all string like DAICE, DAICT, DAIFE, DAIFT, ..., SMNFT (1st list items 2nd list items 3rd list items 4th list items 5 list items) and store them to a new 1d list.

Anyone please help! Many thanks!

I tried using for loop but didn't figure out...

CodePudding user response:

from itertools import product

lst = [['D', 'S'], ['A', 'M'], ['I', 'N'], ['C', 'F'], ['E', 'T']]

lst2 = list(map(''.join, product(*lst)))

print(lst2)

Try the above snippet.

  • Related