I have a list of strings and I need to create a function that prints out n elements of the list each time it is run. For instance:
book1 = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o']
Expected output first time I run the function if n = 5:
a
b
c
d
e
second time:
f
g
h
i
j
I tried this:
def print_book(book):
printed = book
while printed != []:
for i in range(0, len(book), 5):
new_list = (book[i:i+5])
for el in new_list:
print(el)
break
del(printed[i:i+10])
And I get either the entire list printed out, or I end up printing first n elements each time I run the function. If this question has already been asked, please point it out to me, I would really apreciate it. Thanks!