Zhang Ziyang
Zhang Ziyang

Reputation: 35

For loop problem to for next elements in a list

In python, if I have a list

lst=["Word", "Bar", "List", "Warrior", "When", "Apple", "Car"]

and I want to determine for each element if the next element is a word that begins with W, how could I write my for loop?

Upvotes: 0

Views: 38

Answers (1)

Ramy Ibrahim
Ramy Ibrahim

Reputation: 711

lst=["Word", "Bar", "List", "Warrior", "When", "Apple", "Car"]
for i in range(len(lst) -1):
  if lst[i + 1][0] == "W":
    print(i)

Upvotes: 1

Related Questions