所以我們有一個練習,我們給孩子們,我們需要使用一個列表(或數組),以及'.remove()'方法和一個循環。Python循環,.remove和列表練習
我有以下代碼,代碼無法正常工作。
usernames = [
'Steph','JHG','Greg','Matt','Rodney','David',
'Chris','Sally','Gemma','Pam','Daniel','JHG',
'JHG','Ishmael','Sam', 'JHG','Jacob'
]
for i in range(0,3):
for name in usernames:
usernames.remove('JHG')
print(usernames)
檢查
print (
'Success! all the JHG values have been deleted from the list, onto the next!')
那麼究竟是不是工作? –