def lottery_promoted_links(sr_names, n=10):
 promo_tuples = get_live_promotions(sr_names)
 weights = {p: (p.weight or 0.001) for p in promo_tuples}
 selected = []
 while (weights and (len(selected) < n)):
  s = weighted_lottery(weights)
  del weights[s]
  selected.append(s)
 return selected

def lottery_promoted_links ( sr_names , n = 10 ) : promo_tuples = get_live_promotions ( sr_names ) weights = { p : ( p . weight or 0.001 ) for p in promo_tuples } selected = [ ] while ( weights and ( len ( selected ) < n ) ) : s = weighted_lottery ( weights ) del weights [ s ] selected . append ( s ) return selected
run weighted_lottery to order and choose a subset of promoted links .