go one step back and one step forward in a loop with python

前端 未结 3 1481
天命终不由人
天命终不由人 2021-01-23 17:18

I need to loop in a list containing french words and find an asterisk because I want to concatenate the word before the asterisk and the word after the asterisk each time an ast

3条回答
  •  野性不改
    2021-01-23 17:55

    I think you need a simple code like this:

    words = ['les','engage', '*', 'ment', 'de','la']
    
    for n,word in enumerate (words):
        if word == "*":
            exp = words[n-1] + words[n+1]
            print (exp)
    

    Output:

    "engagement"
    

    With this output, you can subsequently check with your dictionary.

提交回复
热议问题