In this HackerRank Standardize Mobile Number Using Decorators problem solution, You are given N mobile numbers. Sort them in ascending order then print them in the standard format shown below:

+91 xxxxx xxxxx

The given mobile numbers may have +91, 91 or 0 written before the actual 10 digit number. Alternatively, there may not be any prefix at all.

HackerRank Standardize Mobile Number Using Decorators in python problem solution

HackerRank Standardize Mobile Number Using Decorators in python problem solution

def mobile(s):
    l = len(s)
    if l == 10:
        s = '+91' + s
    elif l == 11:
        s = '+91' + s[1:]
    elif l == 12:
        s = '+'+s

    return s[0:3] + ' ' + s[3:8] + ' ' + s[8:]

arr = [raw_input() for i in xrange(int(raw_input()))]
arr2 = [mobile(i) for i in arr]
arr2.sort()
for i in arr2:
    print i