2019-02-15 14:30:38

So I'm trying to count permutations in python.import itertoolslist=

Bitcoin Address:
1MeNca7h6m8du4TV3psN4m4X666p6Y36u5m

2019-02-15 14:37:35

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.

Bitcoin Address:
1MeNca7h6m8du4TV3psN4m4X666p6Y36u5m

2019-02-15 18:09:00

Correct me if I'm wrong, but you've defined list as a string rather than an array.

2019-02-15 18:48:19 (edited by pauliyobo 2019-02-15 18:49:36)

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.

Paul

2019-02-15 21:16:46

Shows what I know haha.
Gotta learn more python.