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"
)的某個元素while循環這個案例。在它到達列表中的元素後,它不應該添加任何內容。停止當達到
這是行不通的嗎? –
使用'放置在地方:'循環你的地方,而不是while-thingie;那麼你不需要任何特殊的空白處理。另外爲什麼不是一個簡單的'len(places)'? –