-1
There I was trying to create a script that did permutation, create a combination of the list items in a new list. Follow the python code:
itens = []
while True:
adition = input('Coloque os itens: ')
if adition == 'end':
break
else:
itens.append(adition)
print(adition)
comb = []
for i in itens:
contagem = 0
while True:
comb.append(i + itens[contagem])
print(comb)
if contagem == len(itens):
break
else:
contagem = contagem + 1
But when I run the command and put the items in the list returns the following error:
Comb.append(i+items[count])
Indexerror: list index out of range
Thank you very much! I didn’t know while worked like this. Just one more question. Why can’t my code test all combinations? If a list has [ 1, 2, 3, 4], the code only forms 11, 12, 13, 14 and not 11,12,13,14,21,22,23,24... and so on. Why this happens if I used the for i in list to read all the list items and create a new combination for each of them?
– skatrouxas s
The code forms all permutations, maybe you made another mistake when fixing it, see it working here
– Andre
Fixed. In the code when I was correcting, I counted before the for, this stopped the loop of repetition since counting did not reset. Thank you!
– skatrouxas s