Martin McBride
Aug 17, 2022

--

I am not convinced by the heapq example. Surely you can just sort the list and take the firsth 3 elements like this:

sorted(k)[:3]

There doesnlt seem to be any good reason to drag in a fairly obscure library and put your data into a special data structure, when yiou can easily do it using basic Python features.

--

--

Martin McBride
Martin McBride

Responses (1)