-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkata1.py
69 lines (29 loc) · 958 Bytes
/
kata1.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
dic={2:2354,1:456,3:32,5:78,4:9}
b=dic.items()
a= sorted(b)
print(a)
for i,j in a:
print(j,end=" ")
print()
#your task is to sort a given string. each word in the string will contain a single number.
# this number is the position the word should have in the result.
# note: numbers can be from 1 to 9. so 1 will be the first word (not 0).
# if the input string is empty, return an empty string.
# the words in the input string will only contain valid consecutive numbers.
def order(sentence):
dic1={}
sentence=sentence.split()
for i in sentence:
for j in i:
if j in "123456789":
dic1[j]=i
b = dic1.items()
a = sorted(b)
return " ".join(l for k,l in a)
print(order("is2 Thi1s T4est 3a"))
print(order("4of Fo1r pe6ople g3ood th5e the2"))
print(order(""))
print()
print()
print()
print()