=====Problem Statement=====
Let's use decorators to build a name directory! You are given some information about N people. Each person has a first name, last name, age and sex ('M' or 'F'). Print their names in a specific format sorted by their age in ascending order i.e. the youngest person's name should be printed first. For two people of the same age, print them in the order of their input.

For Henry Davids, the output should be:
Mr. Henry Davids

For Mary George, the output should be:
Ms. Mary George

=====Input Format=====
The first line contains the integer N, the number of people. N lines follow each containing the space separated values of the first name, last name, age and sex, respectively. 

=====Constraints=====
1≤N≤10

=====Output Format=====
Output N names on separate lines in the format described above in ascending order of age.

Difficulty: introductory

Starter code:

import operator

def person_lister(f):
    def inner(people):
        # complete the function
    return inner

@person_lister
def name_format(person):
    return ("Mr. " if person[3] == "M" else "Ms. ") + person[0] + " " + person[1]

if __name__ == '__main__':
    people = [input().split() for i in range(int(input()))]
    print(*name_format(people), sep='\n')

Solutions:
# Enter your code here. Read input from STDIN. Print output to STDOUT
ar=[]
n=int(input())
for i in range(0,n):
    str_ar=input().strip().split()
    user_name=str_ar[0]+" "+str_ar[1]
    user_age=int(str_ar[2])
    user_sex=str_ar[3]
    user_new_name=""
    if(user_sex=="M"):
        user_new_name="Mr. "+user_name
    else:
        user_new_name="Ms. "+user_name
    ar.append([user_new_name,user_age])

l = sorted(ar, key=lambda tup: tup[1])
for i in range(0,n):
    print((l[i][0]))