def makeDict(ingredient, recipe_lists, counter=0, seen=None):

    """
        It takes an ingredient and a list of recipe ingredients (recipe_lists)

        It returns a dictionary with all the ingredients (keys) that match the 

        given ingredient across all of the recipes in the recipe_lists and 

        their weight (value), sorted by value.

        The weight measure the number of times that ingredient is in combination

        with the given ingredient.

        OUTPUT: dictionary like { ingredient A: 5, ingredient B: 4, ... }

    """

    chains = {}

    counter += 1

    if not seen:
        seen= set()

    if ingredient not in seen:

        seen.add(ingredient)

    chains['name'] = ingredient
    chains['children']=[]

    for rec in recipe_lists:

        ingrs = RecipeIngredient.getAllIngredientsNamesByRecipe(rec.recipe_fk)

        for ingr in ingrs:

            if ingr[0] not in seen:
            # children = [s for s in ingrs if s not in seen]
                seen.add(ingr[0])

                chains['children'].append(ingr[0])

    print "chains",chains

    return chains
def makeDict(ingredient, recipe_lists, counter=0, seen=None):
    """
        It takes an ingredient and a list of recipe ingredients (recipe_lists)

        It returns a dictionary with all the ingredients (keys) that match the 

        given ingredient across all of the recipes in the recipe_lists and 

        their weight (value), sorted by value.

        The weight measure the number of times that ingredient is in combination

        with the given ingredient.

        OUTPUT: dictionary like { ingredient A: 5, ingredient B: 4, ... }

    """

    chains = {}

    counter += 1

    if not seen:
        seen = set()

    if ingredient not in seen:

        seen.add(ingredient)

    chains['name'] = ingredient
    chains['children'] = []

    for rec in recipe_lists:

        ingrs = RecipeIngredient.getAllIngredientsNamesByRecipe(rec.recipe_fk)

        for ingr in ingrs:

            if ingr[0] not in seen:
                # children = [s for s in ingrs if s not in seen]
                seen.add(ingr[0])

                chains['children'].append(ingr[0])

    print "chains", chains

    return chains