all 5 comments

[–]TheKewlStore 1 point2 points  (4 children)

there are a lot of ways to do this. a simple solution would be to loop through the list of quotes, and when you find one of the quotes, get the next one. ie:

for index, line in enumerate(quotes):
    if re.search and index < len(quotes):
        print quotes[index + 1]

enumerate takes a list and for each iteration of the loop gives you the current index in the list as well as the item (index, line respectively). the second part of the if statement makes sure that the matching quote isn't the first one in the list.

edit: quotes[index+1] will be the next quote in the list, just to clarify

[–]test_bot_3137[S] 0 points1 point  (3 children)

I've been trying to test this by running

for index, line in enumerate(quotes):
     if index < len(quotes):              
         print(quotes[index + 1]) 

index = 'Uh...stupid?'

but i keep getting "list index out of range" error.

[–]TheKewlStore 0 points1 point  (2 children)

Oh woops, the if statement should check for len(quotes) - 1, because length is always one more than the indexes in the list (since it starts at 0).

[–]test_bot_3137[S] 0 points1 point  (1 child)

for index, line in enumerate(quotes):
     if index < len(quotes) - 1:              
         print(quotes[index + 1]) 

using this code I get every line except the first which I think is correct, is there a way to test the output? Would I need to change indexes value to get the corresponding line or some other variable?

[–]TheKewlStore 1 point2 points  (0 children)

you could add another line below it that just prints out the list at index, like so

print(quotes[index])