Last active
October 18, 2020 21:17
-
-
Save varokas/4391d9086bbdc7e0ba83bfd9e217d0ac to your computer and use it in GitHub Desktop.
food.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from collections import defaultdict | |
import sys | |
individual_indicator = "east" | |
by_name = defaultdict(list) | |
by_item = defaultdict(list) | |
individual = defaultdict(list) | |
current_name = None | |
count = 0 | |
for line in sys.stdin: | |
l = line.rstrip("\n") | |
l = l.strip() | |
if not l.startswith("-"): | |
current_name = l | |
else: | |
if individual_indicator in current_name: | |
individual[current_name].append(l.strip()) | |
else: | |
item = l[1:].strip() | |
item_count = 1 | |
tokens = item.split(" ") | |
if len(tokens) > 1: | |
if tokens[-1].isnumeric(): | |
item_count = int(tokens[-1]) | |
item = " ".join(tokens[:-1]) | |
for i in range(item_count): | |
by_name[current_name].append(item) | |
by_item[item].append(current_name) | |
count += 1 | |
print(f"สรุป: {count}") | |
for item, names in by_item.items(): | |
print(f"{item} {len(names)}") | |
print() | |
print("---") | |
print() | |
for item, names in by_item.items(): | |
print(f"{item} {len(names)} => {names}") | |
print() | |
print("---") | |
print("ไปรับเองที่บ้่านป้า") | |
print("---") | |
print("") | |
for name, s in individual.items(): | |
print(f"{name}") | |
for l in s: | |
print(f"{l}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment