variables to hold "none" if the list items don't exist

uut_image = image_file[0]
hub_image = image_file[1]
hub_sn_image = image_file[2]

I want the variables to hold "none" (string) if the list items don’t exist.

>Solution :

I think inline if condition should work well in this case

uut_image = image_file[0] if len(image_file) > 0 else 'none'
hub_image = image_file[1] if len(image_file) > 1 else 'none'
hub_sn_image = image_file[2] if len(image_file) > 2 else 'none'

Leave a Reply