How to Find the Smallest Items in a List
To find the smallest items in a list in Python using the heapq module,
we use the heapq.nsmallest() function.
This is shown below.
Inside of this function, we specify 2 values. The first values is how many values
you want to display. The second value is the list you are referring to (in this case, numbers).
If we display the smallest variable above, we get what is shown below:
How to Find the Largest Items in a List
To find the largest items in a list in Python using the heapq module, we use the heapq.nlargest() function.
This is shown below:
If we display the largest variable above, we get what is shown below: