[Tutor] Lists or Dictionary?
alan.gauld@bt.com
alan.gauld@bt.com
Mon Jan 20 12:31:06 2003
> i need to creata a data structure... i don't know what to use...
> it should be something like this:
>
> node[0].name
> node[0].state
Which implies a list of objects.
>or this:
>node['A'].name
>node['A'].state
Which suggests a dictionary of objects.
> i have already done a class...
Good, you need that in either scenario.
> and experimented with lists.... and it works just fine...
So use lists! :-)
> i need to know if access and modifications to the structure
> get slower using a dictionar instead of lists....
No they usually get faster. But if it works "just fine" with lists then
carry on using them. Unless performance is a known problem for you
why add the extra complexity of managing a dictionary when you've
already solved it for lists!?
> it is a big data structure.... 10.000 nodes....
Either lists or dictionaries should be fine.
> and about 10 fields.... (small fields.. numbers and small strings..)
That only affects the class design and has no impact on the
list/dictionary debate. Both will just hold a reference to the object.
HTH,
Alan g.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld/