-3

I am a beginner programmer, while doing some work in Python 2.7, I ran into an issue I can't seem to pass. I am trying to find all permutations of all pairs of digits; out of an array that has 4 digits. Example: array = ["a", "b", "c", "d"] and I would like to see the permutations like this: ab, ac, ad, ba, cd, da... ect... Here is my code so far, I can't figure out the next step:

from itertools import permutations
array = ["a", "b", "c", "d"]
for p in permutations(array):
    print(p)

I would appreciate any help I can get, thank you.

  • Which is confusing you? How to get permutations of length 2 or how to turn the tuple back into a string or something else? – DSM Dec 13 '15 at 22:04

1 Answers1

0

Specify optional parameter r like:

from itertools import permutations
array = ["a", "b", "c", "d"]
for p in permutations(array, r=2):
    print(p)
Žilvinas Rudžionis
  • 1,954
  • 20
  • 28