StopIteration unpredictable bug

Khaled Karam

This function gives me unpredictable StopIteration error. I want to understand what causes such a bug. Cause it sometimes work and sometimes doesn't:

def prepare_dimensions(dimensions, dim_list):
        for dimension in dimensions:
            dimension['info'] = next(dim for dim in dim_list if dimension['id'] == dim['_id'])
FerHai

StopIteration will be raised by next if it is given an empty iterable.

If any of your dimensions doesn't match anything in the dim_list you will get this error because the list comprehension will be empty. Similarly if dim_list is empty you will get this error.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related