First-Fit Decreasing

    This is perhaps the simplest packing heuristic;
    it simply packs items in the next available bin.

    This algorithm differs only from Next-Fit Decreasing
    in having a 'sort'; that is, the items are pre-sorted
    (largest to smallest).

    Complexity O(n^2)

def ffd(items, targets, **kwargs):
    """First-Fit Decreasing

    This is perhaps the simplest packing heuristic;
    it simply packs items in the next available bin.

    This algorithm differs only from Next-Fit Decreasing
    in having a 'sort'; that is, the items are pre-sorted
    (largest to smallest).

    Complexity O(n^2)
    """
    sizes = zip(items, weight(items, **kwargs))
    sizes = sorted(sizes, key=operator.itemgetter(1), reverse=True)
    items = map(operator.itemgetter(0), sizes)
    return ff(items, targets)