Using solution from post : https://stackoverflow.com/questions/29284929/rejecting-zero-values-when-creating-a-list-of-minimum-values-python-field-calc

My goal is to populate my "least" column with the minimum value of 4 "time" columns and to exclude zeroes when calculating.The "least" column format is double and my "time" column format is long integer.

This code seems to work for others but not for my table, I've spent a whole day on this and can't find the culprit.

Here is my pre-logic script code:

def my_min(time, time_1):
  lst = [time, time_1]
  return min([x for x in lst if x !=0])

Image: field calculator results

  • 1
    Please post code samples as text, not screenshots.
    – Dan C
    Apr 23, 2018 at 18:54
  • Why? is the image not clear? are you trying to copy and paste the code? Apr 23, 2018 at 18:56
  • 1
    If anyone is inclined to troubleshoot your code, they are much more likely to do so if they can just copy and paste it rather than re-typing it.
    – Dan C
    Apr 23, 2018 at 19:08
  • One of the rows has probably value 0 for four fields. Thus, list comprehension creates an empty list. Apr 23, 2018 at 19:15
  • Thank you all for the help! An addition of code needs to be implemented to handle when my time values in the same row are all 0. Sounds like that is what the min() function is choking on Apr 23, 2018 at 19:46

1 Answer 1


You're getting the error on cases where all your fields equal 0. The function min() expects at least one value, and it throws an error when min([]). Use an if statement to check if the length of your list > 0, else return 0, or some other value.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.