-
-
Save IndhumathyChelliah/5d4b6c5c3ac1f5dbea5d971b17e614cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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