How to iterate over each string in a list of strings and operate on it's elements

前端 未结 8 1967
别跟我提以往
别跟我提以往 2020-12-25 13:00

Im new to python and i need some help with this.

TASK : given a list --> words = [\'aba\', \'xyz\', \'xgx\', \'dssd\', \'sdjh\']

i need to com

8条回答
  •  無奈伤痛
    2020-12-25 13:04

    c=0
    words = ['challa','reddy','challa']
    
    for idx, word in enumerate(words):
        if idx==0:
            firstword=word
            print(firstword)
        elif idx == len(words)-1:
            lastword=word
            print(lastword)
            if firstword==lastword:
                c=c+1
                print(c)
    

提交回复
热议问题