Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def read_menus(food_cat, *menus):
- """Return a string that summarized amount of items from the same category
- in the menus.
- >>> read_menus("food_cat.txt", "menu1.txt", "menu2.txt")
- 'There are 7 burgers, 4 salads and 5 desserts'
- """
- categories = {}
- counts = {}
- for dish, cat in map(lambda x: x.split(': '), open(food_cat).read().strip().splitlines()):
- categories[dish] = cat
- for m in menus:
- for dish, _ in map(lambda x: x.split(': '), open(m).read().strip().splitlines()):
- counts[categories[dish]] = 1 + counts.setdefault(categories[dish], 0)
- return 'There are {Burger} burgers, {Salad} salads and {Desert} desserts'.format_map(counts)
- if __name__ == '__main__':
- print(read_menus('./food_cat.txt', './menu1.txt', './menu2.txt'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement