fork download
  1. from collections import defaultdict
  2.  
  3. tests_dict = {'test 1': ['Manuel', 'Mariana', 'Filipa'], 'test 2': ['Manuel', 'Filipa', 'Mariana'], 'test 3': ['Mariana', 'Manuel', 'Filipa']}
  4. peps_dict = defaultdict(dict)
  5. for test in tests_dict:
  6. for indx, name in enumerate(tests_dict[test], 1):
  7. peps_dict[name][test] = indx
  8. print(peps_dict)
Success #stdin #stdout 0.02s 10248KB
stdin
Standard input is empty
stdout
defaultdict(<class 'dict'>, {'Mariana': {'test 2': 3, 'test 3': 1, 'test 1': 2}, 'Filipa': {'test 2': 2, 'test 3': 3, 'test 1': 3}, 'Manuel': {'test 2': 1, 'test 3': 2, 'test 1': 1}})