Python Forum

Full Version: ValueError - arg is an empty sequence
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
I'm trying to take the two lowest values off a list and then stop.
So far, the two solutions I have return the same error message i.e. ValueError: min() arg is an empty sequence.
I only get this error message if using "while".
The error goes away if I use "if"...(which adds to the confusion...!)

Thoughts?
Smile
Thanks!

scores = [2,5,52,1,5,23,5,5,6,3,3]
itemsInScores = len(scores)
minimumItemsInScores = len(scores) - 2
lowerValueinScores = 0
indexOfMinimumValue = 0

while itemsInScores > minimumItemsInScores :
    #option1
    lowerValueinScores = min(scores) 
    indexOfMinimumValue = scores.index(lowerValueinScores)
    scores.pop(indexOfMinimumValue)
    #option2
    #scores.pop(scores.index(min(scores)))
scores = [2,5,52,1,5,23,5,5,6,3,3]

print('scores prior to elimination: {}\n'.format(scores))
for x in range(2):
    scores.pop(min(range(len(scores)), key=scores.__getitem__))
print('scores after elimination: {}\n'.format(scores))
results:
Output:
scores prior to elimination: [2, 5, 52, 1, 5, 23, 5, 5, 6, 3, 3] scores after elimination: [5, 52, 5, 23, 5, 5, 6, 3, 3]
looks good, thanks!