loading...

re: Daily Challenge #245 - Sort Santa's Reindeer VIEW POST

FULL DISCUSSION
 

Python 3 solution

    # solution
    sort_reindeer = lambda r: sorted(r, key=lambda n: n.split(" ")[-1])

    # test cases
    cases = [
     ["Dasher Tonoyan", "Dancer Moore", "Prancer Chua", "Vixen Hall", "Comet Karavani", "Cupid Foroutan", "Donder Jonker", "Blitzen Claus"],
     ['Kenjiro Mori', 'Susumu Tokugawa', 'Juzo Okita', 'Akira Sanada'],
     ['Kenjiro Mori', 'Juzo Okita', 'Akira Sanada', 'Susumu Tokugawa'],
     ['Yasuo Kodai', 'Kenjiro Sado', 'Daisuke Aihara', 'Susumu Shima', 'Akira Sanada', 'Yoshikazu Okita', 'Shiro Yabu', 'Sukeharu Nanbu', 'Sakezo Yamamoto', 'Hikozaemon Ohta', 'Juzo Mori', 'Saburo Tokugawa'],
     ['Daisuke Aihara', 'Yasuo Kodai', 'Juzo Mori', 'Sukeharu Nanbu', 'Hikozaemon Ohta', 'Yoshikazu Okita', 'Kenjiro Sado', 'Akira Sanada', 'Susumu Shima', 'Saburo Tokugawa', 'Shiro Yabu', 'Sakezo Yamamoto']
    ]

    for i, case in enumerate(cases):
     print(f'Test case {1+i}; sorted reindeer:\n{sort_reindeer(case)}\n')

Try it online!

code of conduct - report abuse