So I'm trying to count permutations in python.import itertoolslist=
1MeNca7h6m8du4TV3psN4m4X666p6Y36u5m
You are not logged in. Please login or register.
AudioGames.net Forum → Developers room → scratching my head on this
So I'm trying to count permutations in python.import itertoolslist=
import itertools
list="coffee"
for word in itertools.permutations(list):
>>print("".join(word))
items=len(word)
pritems I only prints the length of the word in the list word.
Correct me if I'm wrong, but you've defined list as a string rather than an array.
Hi there
You can solve this by generating a list which contains the permutations items. I've used a list compreension in the following code
I will post 2 solutions, one with the list compreension, the other will achieve the same thing just with an ordinary for loop without embedding in a list compreension. My communication skills suck as my english does, with that said, let's move on
solution 1:
import itertools
list= "coffee"
items = ["".join(word) for word in itertools.permutations(list)]
for i in items:
>print(i)
print(len(items))
solution 2>
import itertools
list = "coffee"
items = []
for word in itertools.permutations(list):
>print("".join(word))
>items.append(word)
print(len(items))
Let me know if you got any problemwith this and I hope I've been clear enough.
AudioGames.net Forum → Developers room → scratching my head on this
Generated in 0.015 seconds (48% PHP - 52% DB) with 11 queries