Hi all. I'm new to the forum, this is my first post =)
I'm trying to create a list containing 3^10 lists, each list has 10 string. Each string can be of 1 or 3 types, for simplicity let them be 'a', 'b','c'.
So basically I wish to generate all possible permutations of a 10-item list, with each item being either 'a', 'b' or 'c'.
I have a script that can generate 3^3 permutations. But I realized repeating this script is highly inefficient. Is there anyway I can modify it so it's able to handle 3^10 or even bigger numbers? Code is listed below.
a = ['a','b','c']
list = []
for i in range(27):
b = (i+3)%3
c = (i+4)%3
list.append([a[b],])
if i <= (27/3)-1:
list[i].append(a[1])
if i <= (27/9)-1:
list[i].append(a[1])
elif i >= 2*(27/9)-1:
list[i].append(a[0])
else:
list[i].append(a[2])
elif i >= 2*(27/3)-1:
list[i].append(a[0])
if i <= 4*(27/9)-1:
list[i].append(a[1])
elif i >= 5*(27/9)-1:
list[i].append(a[0])
else:
list[i].append(a[2])
else:
list[i].append(a[2])
if i <= 7*(27/9)-1:
list[i].append(a[1])
elif i >= 8*(27/9)-1:
list[i].append(a[0])
else:
list[i].append(a[2])
print list