Python Forum
error: max() arg is an empty sequence
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error: max() arg is an empty sequence
#1
Hello everyone, 

I'm trying to compile this code:
for idx, i in enumerate(array):
    if  idx > phaseshift:
        if  abs(i - array[idx - phaseshift]) > 1000 or True:
            self.phasespace_x.append(array[idx - phaseshift])
            self.phasespace_y.append(i + array[idx - phaseshift])
            self.linx = [max(self.phasespace_x),min(self.phasespace_x)]
where the problem was at first in array variable. It was not defined. To reduce the error in the "enumerate " line I defined array as empty list as: array=[]. Because when I defined array as integer I got an error that integer in enumerate cannot be interated . 

Now I have this:
Error:
ValueError: max() arg is an empty sequence
which is quite logic I think because of empty variable array. Could you please tell me how to fix this problem? 

Thank you.
Reply
#2
You could give a default value that's returned by max If the iterable is empty.
values = []
print(max(values, default=0))
Output:
0
Reply
#3
(Oct-10-2016, 08:17 PM)Yoriz Wrote: You could give a default value that's returned by max If the iterable is empty.
values = []
print(max(values, default=0))
Output:
0

Thank you. Problem removed. :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 5,024 Sep-04-2021, 09:16 PM
Last Post: eddywinch82
  Error : "can't multiply sequence by non-int of type 'float' " Ala 3 3,023 Apr-13-2021, 10:33 AM
Last Post: deanhystad
  Empty response to request causing .json() to error t4keheart 1 9,948 Jun-26-2020, 08:35 PM
Last Post: bowlofred
  empty json file error mcmxl22 1 9,981 Jun-17-2020, 10:20 AM
Last Post: buran
  PyODBC error - second parameter to executemany must be a sequence, iterator, or gener RBeck22 1 7,017 Mar-29-2019, 06:44 PM
Last Post: RBeck22
  ValueError - arg is an empty sequence jojotte 2 5,312 Dec-31-2018, 10:07 AM
Last Post: jojotte

Forum Jump:

User Panel Messages

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