Python: How to get every combination in list -


i have large amount of lists of lists. here few:

l1=(['g', 'c', 'a'], ['t', 'c'], ['t', 'c']) l2=(['t', 'c'], ['t', 'c'], ['t', 'c']) 

i need lists this: (so every repeat list list)

l1=['gtt','ctt','att','gcc','ccc','acc','gtc','ctc','atc','gct','cct','act'] l2=['ttt','ctt','tcc','ccc','tct','ctc','ttc','cct'] 

using itertools.product:

>>> [''.join(x) x in itertools.product(*l1)] ['gtt', 'gtc', 'gct', 'gcc', 'ctt', 'ctc', 'cct', 'ccc', 'att', 'atc', 'act', 'acc'] >>> >>> [''.join(x) x in itertools.product(*l2)] ['ttt', 'ttc', 'tct', 'tcc', 'ctt', 'ctc', 'cct', 'ccc'] 

from docs:

equivalent nested for-loops in generator expression. example, product(a, b) returns same ((x,y) x in y in b).

but we're using * argument unpacked argument of l1 a, b, c, d...


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -