-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram_2.py
44 lines (32 loc) · 957 Bytes
/
Program_2.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#sentence = "hello world and practice makes perfect and hello world again"
sentence = str(input("Enter sentence to sort"))
def sortingFun(sentence):
sentence_list = []
tmp=''
for char in sentence:
if char == ' ':
sentence_list += [tmp]
tmp=''
else:
tmp += char
if tmp:
sentence_list += [tmp]
new = []
for i in sentence_list:
if i not in new:
new += [i]
for i in range(len(new)-1,0,-1):
for j in range(i):
if new[j]>new[j+1]:
temp = new[j]
new[j] = new[j+1]
new[j+1] = temp
finalResult = ''
last = len(new)-1
for pos, elem in enumerate(new):
finalResult += str(elem)
if pos != last:
finalResult+=" "
return finalResult
fin_res = sortingFun(sentence)
print(fin_res)