Sunday 15 February 2015

permutation - Way of showing permuations of n-elements in one column in python -



permutation - Way of showing permuations of n-elements in one column in python -

i generate permutations of 3-elements with

import itertools = list(itertools.permutations(['a','b','c',],3))

and receive next output:

[('a', 'b', 'c'), ('a', 'c', 'b'), ('b', 'a', 'c'), ('b', 'c', 'a'), ('c', 'a', 'b'), ('c', 'b', 'a')]

i want create elements appear in vertical row no brackets, commas , quotemarks:

abc acb bac ...

i tried utilize bring together function

b=''.join(a)

but received errors

typeerror: sequence item 0: expected str instance, tuple found

my question how can create permute elements appear in column ?

you got error because every element in a tuple. phone call ''.join() every tuple like:

for item in a: print(''.join(item))

python permutation

No comments:

Post a Comment