[Tutor] Some ways lists and dictionaries can be used unconventionally?

Walter Prins wprins at gmail.com
Mon May 23 01:08:18 CEST 2011


On 22 May 2011 21:29, Tidal Espeon <tidal.espeon at gmail.com> wrote:

> I've been trying to make a text-based character creator program, and it was
> going pretty well. I was debugging it earlier, and I was well on my way. The
> problem is, that its something I have to do at the end of a python book's
> chapter about learning lists and dictionaries, and I didn't use either in my
> code.
>
> I've been trying to think of how lists and dictionaries can be useful (or
> even significantly relevant. storing a bunch of variables just shortens the
> code by a few lines), but I fail to see any significant connection.
> (honestly, i don't get a key-value pair make this sort of program easier to
> make.) :/
>
> Since the book told me to do it, I know there must be something. I'd like
> to be taught some uses of dictionaries besides using it as a semi-literal
> dictionary, and uses of lists besides being conveniently changeable tuples.
> I think I can figure it out myself afterwards.
>
> Please and thank you! :)


Which book are you using and what does the excercise say to do exactly?

Regardless, I'm curious about how you're storing your character information
presently.  Suppose you had to store an arbitrary number of characters
(assuming your'e currently basically dealing with one single character's
attributes only), would your existing data structure still work well for
you?

Regarding lists and dicts -- It often happens in programming that you need
to store lists of things (where the number of things are not neccesarily
known in advance or fixed) or be able to find things based on some
identifying attribute.  Lists and dicts are (some of) the Python language
supplied ingredients for you to be able to do this easily and efficiently.
Don't know if that's enough to help clarify things or not.

HTH,

Walter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110523/c536345b/attachment-0001.html>


More information about the Tutor mailing list