Using while loops to count elements in a list

前端 未结 4 598
陌清茗
陌清茗 2020-12-22 07:23
places = [\"Jack\", \"John\", \"Sochi\"]
count=0
multi_word=0
place  = places[count]
while place != \"Sochi\" and count < len(places):
    if \' \' in place:
             


        
4条回答
  •  心在旅途
    2020-12-22 07:40

    count=0
    place = places[count]
    

    Now place is always places[0], i.e. Jack. Thus the while loop only terminates on the second condition, giving you the list length of 3.

    place = places[count] should go in the loop.

提交回复
热议问题