I'm working with a nested list. I'm using a for loop to iterate through it. Sometimes a particular item in the list is dependent on a subsequent nested list. I tried iterating and using next, but that uses up the items that I have not accessed yet. Here is my list. When I look at the first nested list, I don't want to print it if a subsequent list has data that refers to an apple and says that it was a "bad_apple". There could be future nested lists that are followed by "good_apple", and I would want to print that one.
fruit = [
["apple", "round", "small", "red"],
["banana", "long", "large", "yellow"],
["apple", "round", "large", "bad_apple"]
["apple", "round", "medium", "red"],
["banana", "long", "large", "yellow"],
["apple", "round", "large", "good_apple"]
]
for i in fruit:
# print i only if there is no "bad_apple" in the following 3 nested lists
print i
So in this example, I would not want to print the first apple, the "small" one, but I would want to print the 2nd apple, the "medium" one since it is followed by a subsequent list that has "good_apple" in the list. I only want to see 2 or 3 nested lists into the "future".