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

前端 未结 8 1966
别跟我提以往
别跟我提以往 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:12

    The reason is that in your second example i is the word itself, not the index of the word. So

    for w1 in words:
         if w1[0] == w1[len(w1) - 1]:
           c += 1
         print c
    

    would the equivalent of your code.

提交回复
热议问题