`list()` constructor and `__len__` method

Hi Alexander, it’s possible to adjust your code a couple of different ways and avoid the NotImplementedError.

class A:
    def __iter__(self):
        for i in range(8):
            yield i
    def __len__(self):
        raise NotImplementedError
        
        
list(iter(A()))


[x for x in A()]
1 Like