I managed to solve my problem, but I don't understand the problem itself. Yeah, I've been lucky enough to fix it, but it won't be as useful if I don't understand why I had this problem.
When running a for loop inside an object's function, this loop was always skipping one value of the list, just like if the for loop step was set to 2.
Below is a very very simplified and adapted version of my first code, but it gives a good idea of how it works.
class Food:
def __init__(self, my_list):
self.my_list = my_list
def food_iterator(self):
while True:
for element in self.my_list:
print(element)
Food(['pasta', 'chicken', 'porc', 'cheese', 'lasagna']).food_iterator()
When creating a copy of the original list:
class Food:
def __init__(self, my_list):
self.my_list = my_list
def food_iterator(self):
my_list_copy = [m for m in self.my_list])
while True:
for element in my_list_copy:
print(element)
Food(['pasta', 'chicken', 'porc', 'cheese', 'lasagna']).food_iterator()
it just worked perfectly. But I don't understand why it wasn't working before and why it is now...
I would really appreciate to hear your thoughts!