Retrieving the top 100 numbers from one hundred million of numbers

前端 未结 12 2165
北荒
北荒 2020-11-30 19:36

One of my friend has been asked with a question

Retrieving the max top 100 numbers from one hundred million of numbers

in a rece

12条回答
  •  孤街浪徒
    2020-11-30 20:00

    Suppose mylist is a list of hundred million data. so we can sort the list and take the last hundred data from mylist.

    mylist.sort()

    mylist[-100:]

    Second way:

    import heapq

    heapq.nlargest(100, mylist)

提交回复
热议问题