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.
Jump to: navigation, search
(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

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

def lookup(L, k):

   return L[k:k+1].last()
  1. 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().
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox
EECS @ UM
Tools