Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ivanon = {'math':4, 'english':4, 'physic':4, 'chemistry':4, 'biology':4}
- Netfullin = {'math':5, 'english':4, 'physic':4, 'chemistry':5, 'biology':4}
- Pasternak = {'math':5, 'english':4, 'physic':3, 'chemistry':5, 'biology':4}
- Lenina = {'math':5, 'english':5, 'physic':5, 'chemistry':5, 'biology':5}
- Ivanon = {'math':4, 'english':4, 'physic':4, 'chemistry':4, 'biology':4}
- Doe = {'math':5, 'english':5, 'physic':5, 'chemistry':5, 'biology':5}
- Mustermann = {'math':5, 'english':5, 'physic':5}
- Dvoechnikov = {'math':3, 'english':3, 'physic':3, 'chemistry':3, 'biology':3}
- [{'Name1':{'subj1':note, 'subj2':note, ...},
- {'Name2':{'subj1':note, 'subj2':note, ...}]
- import re
- import ast
- def parse_line(line):
- name,rest = re.split('s*=s*', line)
- d = ast.literal_eval(rest)
- return {name:d}
- filename = r'C:Temp.data774534.txt'
- with open(filename) as f:
- data = [parse_line(line) for line in f]
- #best_ones = [n for x in data for n,d in x.items() if all(val == 5 for val in d.values())]
- best_ones = [n for x in data for n,d in x.items() if sum(d.values()) == 5*len(d)]
- print(best_ones)
- ['Doe', 'Mustermann']
- with open(input_file, 'r') as file:
- for line in file:
- if all([raiting[-1] == '5' for raiting in line[line.index('{') + 1:line.index('}')].split(', ')]):
- print(line[:line.index('=')].strip())
- surname_dict = {surname: eval(_dict) for (surname, _dict) in (
- line.split('=', 1) for line in filter(str.strip, open('file.txt')))}
- import json
- print(json.dumps(surname_dict, indent=4, sort_keys=True))
- # {
- # "Ivanon ": {
- # "biology": 4,
- # "chemistry": 4,
- # "english": 4,
- # "math": 4,
- # "physic": 4
- # },
- # "Lenina ": {
- # "biology": 5,
- # "chemistry": 5,
- # ...
- # }
- # }
- for surname, subjects in surname_dict.items():
- if all((val == 5) for val in subjects.values()):
- print(surname, json.dumps(subjects, indent=4))
- # Lenina
- # {
- # "math": 5,
- # "english": 5,
- # "physic": 5,
- # "chemistry": 5,
- # "biology": 5
- # }
Add Comment
Please, Sign In to add comment