I'm having a problem in my code where I'm trying to check if (in my case) there is a review already created with that title from that reviewer.
For that I'm doing:
def review_result(self):
print("Complete your review")
title = input("Title of the paper: ")
reviewer = input("Reviewer's name: ")
for x in self.__review:
if x == title:
index = self.__review.index(x)
if self.__review[index + 1] == reviewer:
But in my self.__review
list I can have the same title repeated multiple times but all with diferent reviewers, for example: ['Book1', 'Rev1', 'Book1', 'Rev2', 'Book1' Rev3']
When I have 2 reviews from the same paper I can't access the 2nd review because that for x in self.__review
is only searching for the 1st value that apears.
Is there any way I can see the next 'x' in that for x in self.__review
loop?
for x in self.__review
is iterating over the entire list. The problem is, as @TomServo pointed out, you've chosen the wrong data structure. Not knowing what your ultimate goal is, I would suggest trying a dict where the keys are the books and the values are a list of reviews. For your data, it would look like{"Book1": ["Rev1", "Rev2", "Rev3"]}
{"rev1":"book1", "rev2":"book1"}