Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Ship Teams by Smerda
def two_teams(sailors):
"""
return list of lists with sailors sorted by name and divided into two teams based on their age
first nested list contains sailors aged between 20 > age > 40 - outside_aged
second nested list contains sailors aged between 20 <= age <= 40 - middle_aged
"""
outside_aged = []
middle_aged = []
[middle_aged.append(name) if 20 <= age <= 40 else outside_aged.append(name) for name, age in sailors.items()]
return [sorted(outside_aged), sorted(middle_aged)]
if __name__ == '__main__':
print("Example:")
print(two_teams({'Smith': 34, 'Wesson': 22, 'Coleman': 45, 'Abrahams': 19}))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert two_teams({
'Smith': 34,
'Wesson': 22,
'Coleman': 45,
'Abrahams': 19}) == [
['Abrahams', 'Coleman'],
['Smith', 'Wesson']
]
assert two_teams({
'Fernandes': 18,
'Johnson': 22,
'Kale': 41,
'McCortney': 54}) == [
['Fernandes', 'Kale', 'McCortney'],
['Johnson']
]
print("Coding complete? Click 'Check' to earn cool rewards!")
Sept. 24, 2018
Comments: