def random_weighted_sample(mapping, k):
 if (k > len(mapping)):
  raise ValueError('sample larger than population')
 sample = set()
 while (len(sample) < k):
  sample.add(weighted_choice(mapping))
 return list(sample)

def random_weighted_sample ( mapping , k ) : if ( k > len ( mapping ) ) : raise ValueError ( 'sample larger than population' ) sample = set ( ) while ( len ( sample ) < k ) : sample . add ( weighted_choice ( mapping ) ) return list ( sample )
return k items without replacement from a weighted sample .