【发布时间】:2013-10-10 04:09:31
【问题描述】:
places= ["Home","In-n Out Burger", "John's house", "Santa Monica Pier", "Staples center", "LA Dodgers stadium", "Home"]
def placesCount(places):
multi_word = 0
count = 0
while True:
place = places[count]
if ' ' in place and place!='LA Dodgers stadium' **""" or anything that comes after LA dogers stadium"""** :
multi_word += 1
if '' in place and place!='LA Dodgers stadium' """ **or anything that comes after LA dogers stadium**""":
count += 1
print (count, "places to LA dodgers stadium"), print (multi_word)
placesCount(places)
我基本上想知道在这种情况下,当 while 循环到达列表的某个元素 ("LA Dodgers Stadium") 时,如何阻止它添加到列表中。在到达列表的那个元素之后,它不应该添加任何东西。
【问题讨论】:
-
这不行吗?
-
使用
for place in places:来循环你的位置而不是while-thingie;那么您不需要对空格进行任何特殊处理。还有为什么不简单的len(places)?
标签: python loops while-loop