Example #1
0
def get_cost_per_item(shoplist):
    """Function to generate dictionary of combined data.

    Args:
        shoplist(dict): Dictionary of item and it quantity.

    Returns:
        dict: new dictionary keyed by the name of the fruit with the total cost
        per-item reflected.

    Examples:

        >>> get_cost_per_item({'Lime': 12, 'Red Pear': 4, 'Peach': 24, 'Beet': 1
        })
        {'Lime': 7.08, 'Peach': 95.76, 'Red Pear': 9.96}
    """
    return {key: FRUIT.get(key) * value for key, value in shoplist.iteritems()
            if FRUIT.get(key)}
def get_cost_per_item(shoplist):
    """
    Args:
        shoplist (dict):  Shopping list
    Returns:
        dict: Fruit total cost per item keyed by fruits
    Examples:
        >>> get_cost_per_item({'Black Plum': 8,
                               'Bosc Pear': 4})
        {'Bosc Pear': 7.96, 'Black Plum': 23.92}
    """
    return {key: numfruits * FRUIT[key] for key,
            numfruits in shoplist.iteritems() if key in FRUIT.keys()}
def get_cost_per_item(shoplist):
    """This function gets the cost per item.

    Args:
        shoplist(dict): A dictionary containing the item & its quantity.

    Returns:
        Dict: a new dict containing the cost for each item found in FRUIT.

    Examples:
    >>>get_cost_per_item({'Lime': 12, 'Red Pear': 4, 'Peach': 24, 'Beet': 1})
    {'Lime': 7.08, 'Peach': 95.76, 'Red Pear': 9.96}
    """
    return dict([(k, r * FRUIT.get(k)) for k, r in shoplist.iteritems()
                 if k in FRUIT])
Example #4
0
def get_cost_per_item(shoplist):
    """ a fucion get cost of items
    args:
        shoplist(dict): a dictionary called shoplist which keys are item name
                        as found in FRUIT and the value should be an integer
                        indicating the number of units to purchase.
    return:
        None
    example:
        >>> print shoplist
        {'Lime': 12, 'Red Pear': 4, 'Peach': 24, 'Beet': 1}
        >>> get_cost_per_item({'Lime': 12, 'Red Pear': 4,
                                'Peach': 24, 'Beet': 1})
        {'Lime': 7.08, 'Peach': 95.76, 'Red Pear': 9.96}
    """

    results = {keys: shoplist[keys] * FRUIT[keys] for keys in shoplist.keys()
               if keys in FRUIT.keys()}

    return results
Example #5
0
def get_cost_per_item(shoplist):
    """A function named get_cost_per_item().
    The key of shoplist should be the item name as found in FRUIT
    The value of shoplist should be an integer indicating
    the number of units to purchase. Return, a new dictionary
    keyed by the name of the fruit with the total cost per-item reflected

    Argument:
    a dictionary called shoplist.

    Return:
    a new dictionary keyed with the total cost per-item reflected.

    Example:"""

    for cfruit, count in shoplist.iteritems():
        for pfruit, price in FRUIT.iteritems():
            if cfruit == pfruit:
                print pfruit, (count * price), count, price
    return
Example #6
0
def get_cost_per_item(shoplist):
    """Creates dict keyed by fruit name.

    Args:
        shoplist (dict): Dictionary of items.

    Returns:
        dict: Keyed by fruit name and total cost/item.

    Examples:
        >>> get_cost_per_item({'Lime': 12, 'Red Pear': 4,
        'Peach': 24, 'Beet': 1})
        {'Lime': 7.08, 'Peach': 95.76, 'Red Pear': 9.96}

        >>> get_cost_per_item({''Red Plum': 3,
        'Bosc Pear': 5, 'Key Lime': 2, 'Beet': 1})

        {'Red Plum': 8.97, 'Key Lime': 7.98, 'Bosc Pear': 9.95}
    """
    return {k: v * z for k, v in shoplist.iteritems()
            for x, z in FRUIT.iteritems() if k == x}
Example #7
0
def get_cost_per_item(shoplist):
    
    """Returns Sum of individual items in a shopping list.

    Args:
    Dictionary list (DICT).

    Returns:
    Number: Returns string from FRUIT.data and its sum.

    Examples:
    >>> get_cost_per_item({'Lime': 12, 'Red Pear': 4, 'Peach': 24, 'Beet': 1})
    {'Lime': 7.08, 'Peach': 95.76, 'Red Pear': 9.96}
    """
    T = 0
    S = {}
    for k, v in shoplist.iteritems():
        if k in FRUIT.keys():
            T = v * FRUIT[k]
            S.update({k:T})
    return S