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