Python‎ > ‎itertools‎ > ‎

itertools.combinations_with_replacement()

http://www.adilwaseem.com/

Definition
Return successive r-length combinations of elements in the iterable allowing individual elements to have successive
repeats.

Syntax
itertools.combinations_with_replacement(x, n)

Parameters
x=iterable
n-number

Example
The return is equal to:
 import itertools
set={"Python", "Lake", "learning", "Center"}
y=itertools.combinations_with_replacement(set,2)
for value in y: print(value)

>>> 
('learning', 'learning')
('learning', 'Lake')
('learning', 'Center')
('learning', 'Python')
('Lake', 'Lake')
('Lake', 'Center')
('Lake', 'Python')
('Center', 'Center')
('Center', 'Python')
('Python', 'Python')
>>>

Comments