In this HackerRank Decorators 2 - Name Directory problem solution You are given some information about N people. Each person has a first name, last name, age, and sex. 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.

HackerRank Decorators 2 - Name Directory in python problem solution

HackerRank Decorators 2 - Name Directory in python problem solution

# Enter your code here. Read input from STDIN. Print output to STDOUT
from operator import itemgetter
list = []
for i in xrange(input()):
    list.append(raw_input().split(' '))
list.sort(key=itemgetter(2))
for id in list:
    print ('Mr.' if  id[3]=='M' else 'Ms.'), id[0], id[1]