def take_using_weights(items, weights):
 assert isinstance(items, list)
 assert isinstance(weights, list)
 assert all((isinstance(i, int) for i in weights))
 assert (len(items) == len(weights))
 assert (len(items) > 0)
 already_taken = [0 for i in items]
 item_count = len(items)
 max_weight = max(weights)
 i = 0
 while True:
  adding = True
  while adding:
   adding = False
   for (item_i, item, weight) in zip(range(item_count), items, weights):
    if (already_taken[item_i] < ((i * weight) / float(max_weight))):
     (yield item)
     already_taken[item_i] += 1
     adding = True
  i += 1

def take_using_weights ( items , weights ) : assert isinstance ( items , list ) assert isinstance ( weights , list ) assert all ( ( isinstance ( i , int ) for i in weights ) ) assert ( len ( items ) == len ( weights ) ) assert ( len ( items ) > 0 ) already_taken = [ 0 for i in items ] item_count = len ( items ) max_weight = max ( weights ) i = 0 while True : adding = True while adding : adding = False for ( item_i , item , weight ) in zip ( range ( item_count ) , items , weights ) : if ( already_taken [ item_i ] < ( ( i * weight ) / float ( max_weight ) ) ) : ( yield item ) already_taken [ item_i ] += 1 adding = True i += 1
generator that keeps yielding items from the items list .