"Tidal Espeon" <tidal.esp...@gmail.com> wrote
I've been trying to make a text-based character creator program, ...chapter about learning lists and dictionaries, ... I've been trying to think of how lists and dictionaries can be useful ... but I fail to see any significant connection.

OK, Assuming your characters attributes have names, would it be useful to have all the attributes of your character accessible by looking up their name? As the value part of a dictionary say?

And since you have a bunch of characters to manage wouldn't it be useful to have them stored in a collection, maybe a list say? Or even a dictionary where the key is the characters name? So we wind up with a dictionary full of characters, each of which is a dictionary of attributes.

Then we can do things like:

characters["Tidal"]["strength"] = 45
print characters["Alan"]["Weapons"]

Which is probably easier to read than using fixed variables like player1_strength and player1_name which is pretty much what you would need to do without a dictionary or list.

Does that help?

--
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

Reply via email to