Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def start_spring(**kwargs):
- result = []
- fl_by_type = {}
- for flower_, type_ in kwargs.items():
- if type_ not in fl_by_type:
- fl_by_type[type_] = []
- fl_by_type[type_].append(flower_)
- sorted_types = sorted(fl_by_type.items(), key=lambda kvp: (-len(kvp[1]), kvp[0]))
- for types, flowers in sorted_types:
- result.append(f'{types}:\n')
- result.append('\n'.join('-' + fl for fl in sorted(flowers)) + '\n')
- return ''.join(result).strip()
- example_objects = {"Water Lilly": "flower",
- "Swifts": "bird",
- "Callery Pear": "tree",
- "Swallows": "bird",
- "Dahlia": "flower",
- "Tulip": "flower",}
- print(start_spring(**example_objects))
- example_objects = {"Swallow": "bird",
- "Thrushes": "bird",
- "Woodpeckers": "bird",
- "Swallows": "bird",
- "Warblers": "bird",
- "Shrikes": "bird",}
- print(start_spring(**example_objects))
- example_objects = {"Magnolia": "tree",
- "Swallow": "bird",
- "Thrushes": "bird",
- "Pear": "tree",
- "Cherries": "tree",
- "Shrikes": "bird",
- "Butterfly": "insect"}
- print(start_spring(**example_objects))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement