parameters: (self, population, k)
return_statement: return retval
docstring: Return a k-length list of unique elements chosen from the population sequence.
docstring_summary: Return a k-length list of unique elements chosen from the population sequence.
docstring_tokens: Return a k - length list of unique elements chosen from the population sequence .
function: def sample(self, population, k):
          """Return a k-length list of unique elements chosen from the population sequence."""
  
          num_choices = len(population)
          if k > num_choices:
              raise ValueError("sample larger than population")
  
          retval = []
          selected = {}  # we emulate a set using a dict here
          for i in range(k):
              r = None
              while r is None or r in selected:
                  r = self.randrange(num_choices)
              retval.append(population[r])
              selected[r] = 1
          return retval
function_tokens: def sample ( self , population , k ) : num_choices = len ( population ) if k > num_choices : raise ValueError ( "sample larger than population" ) retval = [ ] selected = { } # we emulate a set using a dict here for i in range ( k ) : r = None while r is None or r in selected : r = self . randrange ( num_choices ) retval . append ( population [ r ] ) selected [ r ] = 1 return retval