Rhizoqueer
Rhizoqueer

Reputation: 167

How can I create a script that examines a list of numbers to determine the second largest number?

list1=[2,8,64,16,32,4]
import heapq
heapq.nlargest(2, list1)

This is the progress I have made so far. I am (extremely) new to python as you can tell.

Upvotes: 1

Views: 145

Answers (1)

May
May

Reputation: 1167

heapq.nlargest returns a list. SO you need the last element of this list.

heapq.nlargest(2, list1)[-1] --> Gives you the answer.

Upvotes: 1

Related Questions