-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab2.py
46 lines (34 loc) · 969 Bytes
/
lab2.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
numbers_string = input('Please input a string: ')
length = 0
pos = 0
pos_num = -1
num_str = ''
containDec = False
number_list = []
location_list = []
for c in numbers_string:
if '0' <= c <= '9' or c == '.':
if length == 0:
pos_num = pos
if c == '.':
containDec = True
num_str += c
length += 1
else:
if length > 0:
# print(num_str)
if containDec:
number_list.append(float(num_str))
else:
number_list.append(int(num_str))
location_list.append([pos_num, length])
num_str = ''
length = 0
containDec = False
pos += 1
# print(number_list)
# print(location_list)
sorted_location_list = [l for n, l in sorted(zip(number_list, location_list))]
sorted_number_list = sorted(number_list)
print(f'number_list={sorted_number_list}')
print(f'location_list={sorted_location_list}')