Least to greatest


I am trying to write a program that outputs the a list form least to greatest. I wrote it into a file. It keeps giving me the error: ValueError: max() arg is an empty sequence. How can I fix this?

stuff = open("bigsmall.txt", "w")
list = [123,235,53,231,85,795,24,67,8,2]
i = 0
while i <= 11:
x = (max(list))
i += 1
for big in open("bigsmall.txt"):



Your list has 10 elements.

In every iteration of the while loop, you are removing one element. Your loop will be executed 12 times.

At the beginning of the eleventh iteration, your list is empty.

And that is why you see the error. What's the maximum value in the empty list?

To solve this problem you can change condition of while:

while i <= 9:

or better yet, use len to get the correct number of steps:

length = len(list)
while i < length:


Thank you. I that was what I was missing.


You're very welcome :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.