File tree Expand file tree Collapse file tree 1 file changed +14
-17
lines changed
Expand file tree Collapse file tree 1 file changed +14
-17
lines changed Original file line number Diff line number Diff line change 44Domain : Python
55Author : Ahmedur Rahman Shovon
66Created : 15 July 2016
7+ Updated : 3 April 2021
78Problem : https://www.hackerrank.com/challenges/decorators-2-name-directory/problem
89'''
9- # Enter your code here. Read input from STDIN. Print output to STDOUT
10- ar = []
11- n = int (raw_input ())
12- for i in range (0 ,n ):
13- str_ar = raw_input ().strip ().split ()
14- user_name = str_ar [0 ]+ " " + str_ar [1 ]
15- user_age = int (str_ar [2 ])
16- user_sex = str_ar [3 ]
17- user_new_name = ""
18- if (user_sex == "M" ):
19- user_new_name = "Mr. " + user_name
20- else :
21- user_new_name = "Ms. " + user_name
22- ar .append ([user_new_name ,user_age ])
2310
24- sorted = sorted (ar , key = lambda tup : tup [1 ])
25- for i in range (0 ,n ):
26- print sorted [i ][0 ]
11+ import operator
12+ def person_lister (func ):
13+ def inner (people ):
14+ return [func (p ) for p in sorted (people , key = lambda x : (int (x [2 ])))]
15+ return inner
16+
17+ @person_lister
18+ def name_format (person ):
19+ return ("Mr. " if person [3 ] == "M" else "Ms. " ) + person [0 ] + " " + person [1 ]
20+
21+ if __name__ == '__main__' :
22+ people = [input ().split () for i in range (int (input ()))]
23+ print (* name_format (people ), sep = '\n ' )
You can’t perform that action at this time.
0 commit comments