def a_dct(l, m): tmp = dct(l, type=2) tmp_idx = sorted(range(len(tmp)), key=lambda k: -abs(tmp[k])) return tmp[tmp_idx[:m]].tolist()