In this Standardize mobile number using decorators problem, You are given mobile numbers. Sort them in ascending order then print them in the standard format +91 XXXX XXXX.


HackerRank Standardize mobile number using decorators solution in python


Problem solution in Python 2 programming.

def mobile(func):
    def inner(s):
        return sorted([func(i) for i in s])
    return inner
@mobile
def f(num):
    return "+91" + " " + num[-10:-5] + " " + num[-5:]
n = int(raw_input())
s = [raw_input() for _ in xrange(n)]
print "\n".join(f(s))


Problem solution in Python 3 programming.

def wrapper(f):
    def fun(l):
        f(["+91 "+c[-10:-5]+" "+c[-5:] for c in l])
    return fun


Problem solution in pypy programming.

def wrapper(f):
    def fun(l):
        # complete the function
        f("+91 "+c[-10:-5]+" "+c[-5:] for c in l)
    return fun


Problem solution in pypy3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
ll = [input() for _ in range(int(input()))]

def wrapper(fun):
    def phone(ll):
        fun(["+91 "+cn[-10:-5]+" "+cn[-5:] for cn in ll])
    return phone

@wrapper
def sphone(ll):
    print(*sorted(ll), sep='\n')

sphone(ll)