Skip to content

Commit 59d3fad

Browse files
authored
Merge pull request #25 from HighnessAtharva/patch-5
Update Decorators2NameDirectory.py
2 parents b9826f6 + a0abec9 commit 59d3fad

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

ClosuresandDecorators/Decorators2NameDirectory.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
7+
Updated : 3 April 2021
78
Problem : 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')

0 commit comments

Comments
 (0)