Python Forum
ValueError - arg is an empty sequence
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError - arg is an empty sequence
#1
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)))
Reply
#2
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]
Reply
#3
looks good, thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item() Rejoice 6 3,187 Aug-25-2020, 03:50 PM
Last Post: Rejoice
  ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item() bongielondy 2 14,076 Nov-27-2019, 03:25 PM
Last Post: ThomasL
  ValueError: dictionary update sequence element #0 has length 1; 2 Jmekubo 4 35,177 Apr-28-2019, 07:25 PM
Last Post: Jmekubo
  Python- Help with try: input() except ValueError: Loop code to start of sequence Aldi 2 6,195 Mar-08-2018, 03:46 AM
Last Post: Larz60+
  error: max() arg is an empty sequence kentman234 2 44,499 Oct-10-2016, 08:34 PM
Last Post: kentman234

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020