5 Answers
+ 5
a = [0]
for i in a:
a.append(0)
+ 5
You can use the ( while True )
+ 4
You can use generators:
def generate_infinitely():
while True:
yield None
for i in generate_infinitely():
print(i)
+ 4
There are also infinite generators in itertools.
from itertools import repeat
for x in repeat(42):
print(x)
+ 3
You can also write a class with an iterator protocol, that never stops dishing out values.
Running a for loop on an instance of that class would make it run forever.
See here:
https://code.sololearn.com/c2qlPZiFXHTL/?ref=app