Dynamically create loops in Python and store some values -
is possible dynamically create loops in python , store values?
for illustration 2 loop of loops:
for word1 in word_list: word2 in word_list: final_word=word1+word2 a 3 loop of loops:
for word1 in word_list: word2 in word_list: word3 in word_list: final_word=word1+word2+word3
are trying n-combinations of words in list, i.e. if list ['a','b','c'], want ['aaa','aab','aac','aba','abb','abc','aca',etc...]? if so, map bring together on product, repeat value how many words want join:
map(''.join, itertools.product(wordlist, repeat=n)) python
No comments:
Post a Comment