Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sort_kids(kids_list, categories, collection, by_name=False):
- for el in collection:
- if by_name:
- criteria, behavior = el
- matching_kids = [kid for kid in kids_list if kid[1] == criteria]
- else:
- criteria, behavior = el.split('-')
- matching_kids = [kid for kid in kids_list if str(kid[0]) == criteria]
- if len(matching_kids) == 1:
- kid = matching_kids[0]
- categories[behavior].append(kid[1])
- kids_list.remove(kid)
- def output(categories):
- result = []
- for cat, kids in categories.items():
- if kids:
- result.append(f"{cat}: {', '.join(kids)}")
- return "\n".join(result)
- def naughty_or_nice_list(kids_list, *commands, **keywords):
- sorted_by_behavior = {
- "Nice": [],
- "Naughty": [],
- "Not found": []
- }
- sort_kids(kids_list, sorted_by_behavior, commands)
- sort_kids(kids_list, sorted_by_behavior, keywords.items(), by_name=True)
- for kid in kids_list:
- sorted_by_behavior["Not found"].append(kid[1])
- return output(sorted_by_behavior)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement