def applyItemGroupings(itemCounts):
    groupItemPrices = getGroupItemPrices()
    groupsByLargestSaving = sorted(list(groupItemPrices.keys()), key=(lambda group: groupItemPrices[group][0]), reverse=True)
    for group in groupsByLargestSaving:
        while True:
            groupCounts = collections.defaultdict(int)
            for groupItem in group:
                if itemCounts[groupItem]:
                    groupCounts[groupItem] += 1
                    itemCounts[groupItem] -= 1
                else:
                    for (item, count) in groupCounts.items():
                        itemCounts[item] += count
                    break
            else:
                itemCounts[group] += 1
                continue
            break
def applyItemGroupings(itemCounts):
    groupItemPrices = getGroupItemPrices()
    groupsByLargestSaving = sorted(list(groupItemPrices.keys()), key=(lambda group: groupItemPrices[group][0]), reverse=True)
    for group in groupsByLargestSaving:
        while True:
            groupCounts = collections.defaultdict(int)
            for groupItem in group:
                if itemCounts[groupItem]:
                    groupCounts[groupItem] += 1
                    itemCounts[groupItem] -= 1
                else:
                    for (item, count) in groupCounts.items():
                        itemCounts[item] += count
                    break
            else:
                itemCounts[group] += 1
                continue
            break