HackerRank Python - Decorators 2 - Name Directory

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. 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.

  1. import operator
  2. def person_lister(f):
  3. def inner(people):
  4. return map(f, sorted(people, key=lambda x: int(x[2])))
  5. return inner
  6. @person_lister
  7. def name_format(person):
  8. return ("Mr. " if person[3] == "M" else "Ms. ") + person[0] + " " + person[1]
  9. if __name__ == '__main__':
  10. people = [input().split() for i in range(int(input()))]
  11. print(*name_format(people), sep='\n')
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]

donate a cup of tea :)

Join Our Facebook Group

Share this solution


Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube