-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.py
More file actions
29 lines (25 loc) · 918 Bytes
/
program.py
File metadata and controls
29 lines (25 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def get_combination(words,n):
words=sorted(words)
items=list(range(len(words)))
old_combination=[[]]
new_combinations=[]
for i in range(n):
new_combinations=[]
for combination in old_combination:
for item in items:
if (combination and item> combination[-1] or len(combination)==0):
new_combination.append(combination+[item])
old_combination=new_combinations
word_combinations=[]
for combination in new_combinations:
word_combination=[]
for index in combination:
word_combination.append(word[index])
word_combinations.append(tuple(word_combination))
return sorted(set(word_combinations))
n=input().split()
length=len(n)
for i in range(1,length+1):
all_combination=get_combination(n,i)
for combination in all_combination:
print(" ".join(combination))