# This program takes a list of employee names and sorts them
# alphabetically by last name. Then, it creates usernames for
# each employee by using the first five letters of their last
# name, followed by the first two letters of their first name.
from functools import reduce
# List of names
names_list = ['Frank Harrelson', 'Bob Sharles', 'Bob Tranklin', 'Bob Grody', 'Hank Charles', 'Bob Rarrelson',
'Mack Slobson', 'John Jonones', 'Rob Wranklin', 'Tom Simpsonian', 'Rob Rearrelson', 'John Moodys',
'Frank Shones', 'John Harrelson','Frank Quhorles', 'Tom Pharles', 'Frank Fwanklin', 'Frank Charleston',
'John Arles', 'John Georanklin', 'Frank Dobsonsoson', 'Diane Johnston', 'Dob Scone', 'Michael Scarn',
'Goldie Hawn', 'Billie Holliday', 'Woody Harrelson', 'Arthur Rubinstein', 'Thomas Edison', 'Robert Goulet']
# Using the sort() method to sort names
names_list.sort(key = lambda name:name.split()[-1].lower()) #lambda expression to control sorting
print(names_list)
# Using the map() method to take each name and retrieve only the first
# five characters of last name, and first two characters of first name.
usernames = list(map(lambda name: name.split()[-1][:5].lower() + name.split()[0][:2].lower(), names_list))
# ^^^ splits the names into first and name,
# ^^^ and takes the respected amount of characters
# ^^^ (remove .lower() if capitalization is wished to be kept)
print(usernames)