parameters: (items, bins, targets)
return_statement: return arrangements
docstring: Shuffle items into bins in all possible arrangements that satisfy these conditions:
        1) All bins must have at least one item.
        2) Any bins with a specified target must have exactly that number of items.
docstring_summary: Shuffle items into bins in all possible arrangements that satisfy these conditions:
        1) All bins must have at least one item.
        2) Any bins with a specified target must have exactly that number of items.
docstring_tokens: Shuffle items into bins in all possible arrangements that satisfy these conditions : 1 ) All bins must have at least one item . 2 ) Any bins with a specified target must have exactly that number of items .
function: def shuffle_into_bins(items, bins, targets):
      """
      Shuffle items into bins in all possible arrangements that satisfy these conditions:
        1) All bins must have at least one item.
        2) Any bins with a specified target must have exactly that number of items.
      """
      arrangements = []
  
      # If there are items not yet in a bin, place the first item in each possible bin and call this
      # function recursively.
      if items:
  
          # If there are only enough items to fill the empty bins, then we will only put the next
          # item in an empty bin (because putting it in a non-empty bin would prevent us from filling
          # all bins).
          empty_bin_count = sum(1 for x in bins if not x)
          only_put_in_empty = len(items) <= empty_bin_count
  
          for i, _ in enumerate(bins):
  
              # Don't put an item in a bin if that bin is already at capacity.
              if targets[i] and len(bins[i]) >= targets[i]:
                  continue
  
              if only_put_in_empty and bins[i]:
                  continue
  
              bins_copy = [list(x) for x in bins]
              bins_copy[i].append(items[0])
              arrangements += shuffle_into_bins(items[1:], bins_copy, targets)
  
      # If all items are in a bin, all bins have at least one item and any bins with a target have
      # the appropriate amount, then add the arrangement to the results.
      elif all(x for x in bins) and \
              all([not target or target == len(bins[i]) for i, target in enumerate(targets)]):
          arrangements.append(bins)
      return arrangements
function_tokens: def shuffle_into_bins ( items , bins , targets ) : arrangements = [ ] # If there are items not yet in a bin, place the first item in each possible bin and call this # function recursively. if items : # If there are only enough items to fill the empty bins, then we will only put the next # item in an empty bin (because putting it in a non-empty bin would prevent us from filling # all bins). empty_bin_count = sum ( 1 for x in bins if not x ) only_put_in_empty = len ( items ) <= empty_bin_count for i , _ in enumerate ( bins ) : # Don't put an item in a bin if that bin is already at capacity. if targets [ i ] and len ( bins [ i ] ) >= targets [ i ] : continue if only_put_in_empty and bins [ i ] : continue bins_copy = [ list ( x ) for x in bins ] bins_copy [ i ] . append ( items [ 0 ] ) arrangements += shuffle_into_bins ( items [ 1 : ] , bins_copy , targets ) # If all items are in a bin, all bins have at least one item and any bins with a target have # the appropriate amount, then add the arrangement to the results. elif all ( x for x in bins ) and all ( [ not target or target == len ( bins [ i ] ) for i , target in enumerate ( targets ) ] ) : arrangements . append ( bins ) return arrangements