Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jul 7, 2020
Embed
What would you like to do?
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