solutions

Negative Numbers Iterators

The NegativeNumbersIterator is really similar to NumbersIterator, with the difference that it should count backwards starting from 0.

iterator = iter(NegativeNumbersIterator())

print(next(iterator))  # 0
print(next(iterator))  # -1
print(next(iterator))  # -2
print(next(iterator))  # -3

Warning! This is also an infinite iterator.

Test Cases

test negative numbers - Run Test

def test_negative_numbers():
    iterator = iter(NegativeNumbersIterator())

    assert next(iterator) == 0
    assert next(iterator) == -1
    assert next(iterator) == -2
    assert next(iterator) == -3
class NegativeNumbersIterator(object): pass