I tried to iterate over a list again and again but when the first round is finished I have to print dashes. But the dashes are printing before the round gets fully finished. Here is what I tried so far:
from time import sleep as p
lit = [1, 2, 3, 4, 5]
n = 0
while True:
p(1)
print(lit[n])
n = (n+1) % len(lit)
if lit[n] == lit[-1]:
print('-'*80)
I also tried the following condition too but it didn't work
if n == len(lit):
print('-'*80)
here is what I'm getting
1
2
3
4
--------------------------------------------------------------------------------
5
1
.
here is an expected output
1
2
3
4
5
--------------------------------------------------------------------------------
1
.
arris undefined.if n == len(arr):go before you incrementn?n, you'll yield the desired output. Alternatively, testing forn == 0after incrementing would work as wellwhile True: for x in lit: print(x); print dashes; sleep if you really have to