是否可以在Python中动态创建循环并存储一些值?
例如2循环循环:
for word1 in word_list:
for word2 in word_list:
final_word=word1+word2
三循环循环:
for word1 in word_list:
for word2 in word_list:
for word3 in word_list:
final_word=word1+word2+word3
答案 0 :(得分:1)
您是否只是尝试获取列表中所有单词组合,即如果列表为['a','b','c']
,您是否只需要['aaa','aab','aac','aba','abb','abc','aca',etc...]
?如果是这样,只需在产品上映射连接,其中重复值是您要加入的字数:
map(''.join, itertools.product(wordlist, repeat=n))
答案 1 :(得分:0)
BadMagic<string> = {
[x: number]: {
[x: number]: {
[x: number]: BadMagic<string>, // "infinite"
...
},
...
},
toString: {},
charAt: {},
...
}