Python Forum
ValueError - arg is an empty sequence - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: ValueError - arg is an empty sequence (/thread-15015.html)



ValueError - arg is an empty sequence - jojotte - Dec-30-2018

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)))



RE: ValueError - arg is an empty sequence - Larz60+ - Dec-30-2018

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]



RE: ValueError - arg is an empty sequence - jojotte - Dec-31-2018

looks good, thanks!