python笔试题之找出一个列表里出现频次最高的元素(most common elements in a list)
def most_common(seq): d = {} for i in seq: d[i] = d.get(i, 0) + 1 ret = [] for j in sorted(d.items(), reverse=True, key=lambda x:x[1]): if len(ret) == 0: ret