Guest User

Untitled

a guest
Jan 23rd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. Ivanon = {'math':4, 'english':4, 'physic':4, 'chemistry':4, 'biology':4}
  2. Netfullin = {'math':5, 'english':4, 'physic':4, 'chemistry':5, 'biology':4}
  3. Pasternak = {'math':5, 'english':4, 'physic':3, 'chemistry':5, 'biology':4}
  4. Lenina = {'math':5, 'english':5, 'physic':5, 'chemistry':5, 'biology':5}
  5.  
  6. Ivanon = {'math':4, 'english':4, 'physic':4, 'chemistry':4, 'biology':4}
  7. Doe = {'math':5, 'english':5, 'physic':5, 'chemistry':5, 'biology':5}
  8. Mustermann = {'math':5, 'english':5, 'physic':5}
  9. Dvoechnikov = {'math':3, 'english':3, 'physic':3, 'chemistry':3, 'biology':3}
  10.  
  11. import yaml
  12.  
  13. with open(filename) as f:
  14. data = yaml.safe_load(f.read().replace('=',':'))
  15.  
  16. In [94]: data
  17. Out[94]:
  18. {'Doe': {'biology': 5, 'chemistry': 5, 'english': 5, 'math': 5, 'physic': 5},
  19. 'Dvoechnikov': {'biology': 3,
  20. 'chemistry': 3,
  21. 'english': 3,
  22. 'math': 3,
  23. 'physic': 3},
  24. 'Ivanon': {'biology': 4,
  25. 'chemistry': 4,
  26. 'english': 4,
  27. 'math': 4,
  28. 'physic': 4},
  29. 'Mustermann': {'english': 5, 'math': 5, 'physic': 5}}
  30.  
  31. [{'Name1':{'subj1':note, 'subj2':note, ...},
  32. {'Name2':{'subj1':note, 'subj2':note, ...}]
  33.  
  34. import re
  35. import ast
  36.  
  37. def parse_line(line):
  38. name,rest = re.split('s*=s*', line)
  39. d = ast.literal_eval(rest)
  40. return {name:d}
  41.  
  42. filename = r'C:Temp.data774534.txt'
  43.  
  44. with open(filename) as f:
  45. data = [parse_line(line) for line in f]
  46.  
  47. #best_ones = [n for x in data for n,d in x.items() if all(val == 5 for val in d.values())]
  48. best_ones = [n for x in data for n,d in x.items() if sum(d.values()) == 5*len(d)]
  49. print(best_ones)
  50.  
  51. ['Doe', 'Mustermann']
  52.  
  53. with open(input_file, 'r') as file:
  54. for line in file:
  55. if all([raiting[-1] == '5' for raiting in line[line.index('{') + 1:line.index('}')].split(', ')]):
  56. print(line[:line.index('=')].strip())
  57.  
  58. [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