fork download
  1. def max_all(iterable, *, key):
  2. it = iter(iterable)
  3. max_values = [next(it)]
  4. max_key = key(max_values[0])
  5.  
  6. for x in it:
  7. x_key = key(x)
  8.  
  9. if x_key > max_key:
  10. max_values = [x]
  11. max_key = x_key
  12. elif x_key == max_key:
  13. max_values.append(x)
  14.  
  15. return max_values
  16.  
  17.  
  18. d = {'x1': 2, 'x2': 2}
  19. print(max_all(d, key=d.get))
Success #stdin #stdout 0.02s 27720KB
stdin
Standard input is empty
stdout
['x1', 'x2']