error: max() 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: error: max() arg is an empty sequence (/thread-429.html) |
error: max() arg is an empty sequence - kentman234 - Oct-10-2016 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: which is quite logic I think because of empty variable array. Could you please tell me how to fix this problem? Thank you. RE: error: max() arg is an empty sequence - Yoriz - Oct-10-2016 You could give a default value that's returned by max If the iterable is empty. values = [] print(max(values, default=0))
RE: error: max() arg is an empty sequence - kentman234 - Oct-10-2016 (Oct-10-2016, 08:17 PM)Yoriz Wrote: You could give a default value that's returned by max If the iterable is empty. Thank you. Problem removed. :) |