Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 6, 2020 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/5d4b6c5c3ac1f5dbea5d971b17e614cf to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/5d4b6c5c3ac1f5dbea5d971b17e614cf to your computer and use it in GitHub Desktop.
import itertools
l1=itertools.permutations("ABC")
print (list(l1))#Output:[('A', 'B', 'C'), ('A', 'C', 'B'), ('B', 'A', 'C'), ('B', 'C', 'A'), ('C', 'A', 'B'), ('C', 'B', 'A')]
l2=itertools.permutations([3,2,1])
print (list(l2))#Output:[(3, 2, 1), (3, 1, 2), (2, 3, 1), (2, 1, 3), (1, 3, 2), (1, 2, 3)]
#elements are treated as unique based on their position and not by their value.
l3=itertools.permutations([1,1])
print (list(l3))#Output:[(1, 1), (1, 1)]
l4=itertools.permutations(["ABC"])
print (list(l4))#Output:[('ABC',)]
#r value is mentioned as 2. It will return all different permutations in 2 values.
l5=itertools.permutations([1,2,3,4],2)
print (list(l5))#Output:[(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment