Newbie help- Can multiple instances with multiple names automatically created.

Chris Rebert clp2 at rebertia.com
Mon Jan 4 16:54:41 EST 2010


On Mon, Jan 4, 2010 at 1:32 PM, Shawn Milochik <shawn at milochik.com> wrote:
> You could put them in a dictionary with the key being the name, instead of a list.

To illustrate that for the OP:

name2drink = {}
for booze in liquors:
    for juice in juices:
        name = juice +" "+booze # or however you're naming them
        drink = Bottle(booze, juice)
        name2drink[name] = drink

#example use
favorite = name2drink["apple wine"]
favorite.rating = 9/10

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list