why this code returns "list index out of range" error
Matthew Barrera
I can't work out why this code is returning a "list index out of range error. Any suggestions ?
img = None
data_values = ['2', '3', '4', '5']
print("before condition: ", data_values, type(data_values), len(data_values))
try: if any(value in data_values for value in ('20', '42')) or (img is not None): print("after condition") form_data_values[f'{question}'] = form_data
except Exception as e: print(e)here is the output of that code:
before condition: ['2', '3', '4', '5'] <class 'list'> 4
list index out of range 2 Related questions 5273 How do I make a flat list out of a list of lists? 4357 How to find the index for a given item in a list? 1707 ?">Why not inherit from List<T>? Related questions 5273 How do I make a flat list out of a list of lists? 4357 How to find the index for a given item in a list? 1707 ?">Why not inherit from List<T>? 2987 Why is "1000000000000000 in range(1000000000000001)" so fast in Python 3? 2245 How to remove an element from a list by index 2084 Why is it string.join(list) instead of list.join(string)? 556 Flatten an irregular (arbitrarily nested) list of lists Load 4 more related questions Show fewer related questions Reset to default