我有一种感觉,会被告知去看“入门指南”之类的东西,但我有这个代码:
does = ['my','mother','told','me','to','choose','the']
it = ['my','mother','told','me','to','choose','the']
work = []
while 5 > len(work):
for nope in it:
if nope in does:
work.append(nope)
print (work)
我明白了
['my', 'mother', 'told', 'me', 'to', 'choose', 'the']
为什么会这样?我该如何说服它返回呢?
['my', 'mother', 'told', 'me']
while 5>len(work)
是不合逻辑的,导致了“尤达条件”的名称(https://en.wikipedia.org/wiki/Yoda_conditions)。当然,两种方式都是正确的:) - Andras Deak -- Слава Україні