dask.bag.Bag.topk

dask.bag.Bag.topk

Bag.topk(k, key=None, split_every=None)[源代码]

集合中的 K 个最大元素

可选地按某个键函数排序

>>> import dask.bag as db
>>> b = db.from_sequence([10, 3, 5, 7, 11, 4])
>>> list(b.topk(2))
[11, 10]
>>> list(b.topk(2, lambda x: -x))
[3, 4]