Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- # stwórz słownik z domyślną wartością 0 dla nowych kluczy
- result = defaultdict(int)
- # wczytaj dane z pliku "dane.txt"
- with open("dane.txt") as f:
- for line in f:
- # usuń białe znaki na początku i końcu linii, a następnie podziel linie na klucz i wartość
- key, value = line.strip().strip("()").split(", ")
- # dodaj wartość do słownika pod kluczem
- result[key] += int(value)
- # wyświetl wyniki
- for key, value in result.items():
- print(f"({key}, {value})")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement