[Tutor] lists vs dicts

Sean 'Shaleh' Perry shalehperry@attbi.com
Wed, 27 Mar 2002 07:49:50 -0800 (PST)


> 
> A rhetorical question to help me decide which type to use when -- I'm 
> used to being able to access an array by its numeric index OR its 
> associative index.
> 

use a list when it is just that, a list.  The name dictionary should give a
clue to its preferred usage.  YOu have one word and you want to use it as an
index for some data.

A shopping list is a list.  You just walk it and deal with the items.  An
addressbook is likely a dictionary.  You have 'Tom Thumb' and you want to know
his phone number.

Basically use whatever data structure makes the code easiest.  In python you
generally do not use the integer list indexes in a loop.