from collections import defaultdict
from math import floor

def count_by(lists,  fn = lambda x: x):
    count = defaultdict(int)
    for val in map(fn, lists):
        count[val] += 1
    return dict(count)

count_by([6.1, 4.2, 6.3], floor) # {6: 2, 4: 1}
count_by(['one', 'two', 'three'], len) # {3: 2, 5: 1}
 

 

相关文章:

  • 2022-12-23
  • 2022-02-01
  • 2022-12-23
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
猜你喜欢
  • 2022-12-23
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
相关资源
相似解决方案