Ok. I think I am starting to get it but still not sure how to separate the value from the key. Once I have this...
attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0} MAX_POINTS = 30 How do I set the variable for available_points? available_points = MAX_POINTS - (not sure what goes here) I am pretty sure I will change the values by something like this... attributes["strength"] = input("\nHow many points do you want to assign to strength?: ") Please let me know if this isn't advisable. It seems to work on the surface. On Mon, Dec 6, 2010 at 1:16 PM, Alan Gauld <alan.ga...@btinternet.com>wrote: > > "Al Stern" <albst...@gmail.com> wrote > > > Thanks for the advice. I think I have the dictionary function set up right >> now although I'm still not clear why it is better than the list. >> >> attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0} >> > > Consider where you want to update the points for "health" > > Using two lists you need to loop over the keys list to find the index > of "health" then access the values list to set the points. Something > like this: > > for x in range(len(keys)): > if keys[x] == "health": > values[x] = newValue > > With a dictionary you just need to do > > attributes["health"] = newValue > > That's a lot less typing and will be faster performance too. > I'd also say its a lot easier to see whats happening - its more readable. > > HTH, > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor