# C. lookup(L, k): return the kth item in the mylist, where indexing starts at 0.

From EECS 182

C. lookup(L, k): return the kth item in the mylist, where indexing starts at 0.

(Created page with "# Problem C: return the kth item in L. k starts at 0. # lookup(mylist().append(4).append(3), 1) should be 3 def lookup(L, k): return L[k:k+1].last()") |
|||

Line 4: | Line 4: | ||

def lookup(L, k): | def lookup(L, k): | ||

return L[k:k+1].last() | return L[k:k+1].last() | ||

+ | |||

+ | # You should try doing the problem without the benefit of the indexing operation as well. It is possible to do it with only using last() and pop(). |

## Latest revision as of 02:22, December 15, 2012

- Problem C: return the kth item in L. k starts at 0.
- lookup(mylist().append(4).append(3), 1) should be 3

def lookup(L, k):

return L[k:k+1].last()

- You should try doing the problem without the benefit of the indexing operation as well. It is possible to do it with only using last() and pop().