나는 파이썬에서 재귀에 대해 배우고 나는이 코드를 가지고 :파이썬 재귀 및 목록
def search(l,key):
"""
locates key in list l. if present, returns location as an index;
else returns False.
PRE: l is a list.
POST: l is unchanged; returns i such that l[i] == key; False otherwise.
"""
if l: # checks if list exists
if l[0] == key: # base case - first index is key
return True
s = search(l[1:], key) # recursion
if s is not False:
return s
return False # returns false if key not found
누군가가 라인
s = search(l[1:], key)
정확히 무엇을 나에게 설명 할 수 있습니까? l [1 :]은 목록에 무엇을합니까?
[여기] (http://stackoverflow.com/questions/509211/pythons-slice-notation) –
humm, 코드가 'i [i] == key와 같은 결과를 반환하지 않는 것 같습니다. – laike9m