read the dictionary value from array

Posted by ben martin on Stack Overflow See other posts from Stack Overflow or by ben martin
Published on 2013-11-06T03:40:55Z Indexed on 2013/11/06 3:54 UTC
Read the original article Hit count: 163

Filed under:
|
|
CALORIES = \
    { 'Beef' : 200,     \
     'Chicken' : 140,   \
    }
class Food():
    __slots__ = (
        'cal'           # Calories
    )

def mkFood( name ):
    """Create and return a newly initialized Food item"""
    result = Food()
    result.cal = calorie in dict(CALORIES[1])
    return result

Is that a proper way to the value of the target item in Calories? Like getting 200, 140, such like that.

result.cal = calorie in dict(CALORIES[1])

© Stack Overflow or respective owner

Related posts about python

Related posts about arrays