### itertools(pemutations) in python

Posted:

**Sun Jun 23, 2019 9:33 am**Now, this post will cover some math along with python so bear with me.

I am using permutations from itertools module in python..

What this basically does is gives all possible ways of arranging n amount of objects in r slots.

if i were to enter 123, my output would be

123

132

213

231

312

321

This way of outputting applies to words also where all words are outputted in dictionary order.

Cat will give me

act

atc

cat

cta

tac

tca

Now here comes my problem,

If i put something like boss, it will give
by doing the math I expect 12 words , but i get 24.. This is because of the repeation of the 's' in my input word.

Is there any way to ignore repetations and get output to be 12

Closer scan of output will reveal that every word is repeated exactly twice and you can find a matching pair for every word, which i hope to cancel out

I am using permutations from itertools module in python..

What this basically does is gives all possible ways of arranging n amount of objects in r slots.

if i were to enter 123, my output would be

123

132

213

231

312

321

This way of outputting applies to words also where all words are outputted in dictionary order.

Cat will give me

act

atc

cat

cta

tac

tca

Now here comes my problem,

If i put something like boss, it will give

Code: Select all

```
1) boss
2) boss
3) bsos
4) bsso
5) bsos
6) bsso
7) obss
8) obss
9) osbs
10) ossb
11) osbs
12) ossb
13) sbos
14) sbso
15) sobs
16) sosb
17) ssbo
18) ssob
19) sbos
20) sbso
21) sobs
22) sosb
23) ssbo
24) ssob
```

Is there any way to ignore repetations and get output to be 12

Closer scan of output will reveal that every word is repeated exactly twice and you can find a matching pair for every word, which i hope to cancel out