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}
- import yaml
- with open(filename) as f:
- data = yaml.safe_load(f.read().replace('=',':'))
- In [94]: data
- Out[94]:
- {'Doe': {'biology': 5, 'chemistry': 5, 'english': 5, 'math': 5, 'physic': 5},
- 'Dvoechnikov': {'biology': 3,
- 'chemistry': 3,
- 'english': 3,
- 'math': 3,
- 'physic': 3},
- 'Ivanon': {'biology': 4,
- 'chemistry': 4,
- 'english': 4,
- 'math': 4,
- 'physic': 4},
- 'Mustermann': {'english': 5, 'math': 5, 'physic': 5}}
- [{'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 for (surname, _dict) in (line.split('=', 1) for line in filter(str.strip, open('file.txt'))) if all((val == 5) for val in eval(_dict).values())]
Add Comment
Please, Sign In to add comment