-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecorsort.py
41 lines (30 loc) · 914 Bytes
/
decorsort.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
from functools import wraps
import re
def stdfmt(func):
'''
* Standard number format: +91 ##### #####
* Numbers may start with +91, 91, 0, or no prefix but will all be converted
to use the above format
'''
@wraps(func)
def inner(nums):
fmtnums = []
for num in nums:
res = re.search(r'^(?:\+?91|0)?(\d{10})', num).group(1)
fmtnums.append(f'+91 {res[:5]} {res[5:]}')
# Alternatively - just grab last 10 digits:
# "+91" + " " + number[-10:-5] + " " + number[-5:]
return func(fmtnums)
return inner
# Update numbers to standard format
@stdfmt
def numsort(nums):
# Sort the numbers in ascending order
return sorted(nums)
def main():
nums = int(input())
num_list = [input() for _ in range(nums)]
for num in numsort(num_list):
print(num)
if __name__ == '__main__':
main()