-
-
Save IndhumathyChelliah/6e6f6ef998621d6561255fc06c4935ac 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 | |
#Only one iterable is given | |
l1=itertools.product("ABCD") | |
print (list(l1))#Output:[('A',), ('B',), ('C',), ('D',)] | |
#two iterables are given | |
l2=itertools.product("ABC",[1,2]) | |
print (list(l2))#Output:[('A', 1), ('A', 2), ('B', 1), ('B', 2), ('C', 1), ('C', 2)] | |
#one iterable and repeat is mentioned. | |
l3=itertools.product("xy",repeat=2) | |
print (list(l3))#Output:[('x', 'x'), ('x', 'y'), ('y', 'x'), ('y', 'y')] | |
l4=itertools.product("aa",repeat=2) | |
print (list(l4))#Output:[('a', 'a'), ('a', 'a'), ('a', 'a'), ('a', 'a')] | |
#More than two iterables is mentioned | |
l5=itertools.product([1,2],[3,4],[5,6]) | |
print (list(l5))#Output:[(1, 3, 5), (1, 3, 6), (1, 4, 5), (1, 4, 6), (2, 3, 5), (2, 3, 6), (2, 4, 5), (2, 4, 6)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment