-1

My code is pretty simple. My task is to get every permutation of given string. Compute number of permutations - that's clear - factorial.

Code

s = "aba"
perm = list("".join(string) for string in permutations(s))# all permutations
numberOfPerm = len(perm) #number of permutations
unique = len(list(set(perm))) #number of unique permutations
list.sort(perm) # ascii sorting
format_list = [numberOfPerm, unique]
print("total: {} (unique: {}) ".format(*format_list))
print(perm)

Output of this is

total: 6 (unique: 3) 
['aab', 'aab', 'aba', 'aba', 'baa', 'baa']

The thing is i need it to be like this

 total: 6 (unique: 3) aab, aab, aba, aba, baa, baa

I bumped on various solutions e.g. ''.join(finalArray), but none of them work either in my pycharm or in VPL (virtual programming lab) - traceback errors appear. Thanks for eventual help.

RickertBrandsen
  • 201
  • 4
  • 15

1 Answers1

0
print("total: {} (unique: {}) {}".format(*format_list, ', '.join(perm))
Uriel
  • 15,579
  • 6
  • 25
  • 46
  • This solution doesn't pass VPL, but definitely works in pycharm. File "Anagram.py", line 10 print("total: {} (unique: {}) {}".format(*format_list, ', '.join(perm))) SyntaxError: only named arguments may follow *expression – RickertBrandsen Nov 08 '16 at 10:03
  • Try to change `*format_list` with `format_list[0], format_list[1]` – Uriel Nov 08 '16 at 10:18
  • well seems to be problem with my knowledge of python basics, another kind of failure appeared. I am using `s = str(input())` instead `s = "aba"` and there are two failures in the tests this one `Traceback (most recent call last): File "Ana.py", line 4, in s = str(input()) File "", line 1, in NameError: name 'kladno' is not defined` – RickertBrandsen Nov 08 '16 at 10:37
  • ok..it is the problem with VPL... It is prolly using python 2.x instead of 3.x. So thx for your answer..marking as solved – RickertBrandsen Nov 08 '16 at 21:53