Itertools.combinations¶
This are use for combinatory construct, the usage of this methods is focus provide a series of tuples with all the sequence or set of numbers or letters used in the iterator.
Here r
is an input, it represent the size of different combinations that are possible
Itertools.combinations¶
itertools.combinations() | HackerRank
Problem definition¶
Task
You are given a string.Your task is to print all possible combinations, up to size, of the string in lexicographic sorted order.
Input Format
A single line containing the string and integer value separated by a space.
Output Format
Print the different combinations of string on separate lines.
Sample Input
HACK 2
Implementation¶
s
is the stringn
the length of the combinationfor
loop, using a range that will be from1
to then+1
, range upper limit not inclusive thus the+1
- Second
for
loop this time using thecombination
it is usingsorted()
to sort the string.