0
lines = []
while True:
    line = raw_input()
    if line:
        lines.append(line)
    else:
        break
print lines

This would take line by line in a list. Output is:

In [27]: lines

Out[27]: ['x-xx', 'y->y', '-z->']

How do I access the next letter, currently being at a letter, in the following specified code:

count = 0   # to check how many '->' are there in each line
for sentence in lines:
    for letter in sentence:
        if letter == '-':
            #check if the next character is '>'   (How to code this line)
            #and if so, increment count
        else:
            break

Is there a way out for this kind of for loop, where you don't index letter but iterate on letter itself directly?

saichand
  • 1,165
  • 1
  • 10
  • 25
  • It looks like this thread could help you: https://stackoverflow.com/questions/8899905/count-number-of-occurrences-of-a-given-substring-in-a-string – Jan Aug 24 '17 at 13:49
  • Thanks for that, but actually I want to know the syntax more than the problem at hand, i.e., is there a way to access next element when for loop is written this way... – saichand Aug 26 '17 at 04:05

0 Answers0