Summing a 2D list

Karsten Heymann karsten.heymann at blue-cable.net
Fri Jun 13 11:55:44 EDT 2008


Hi Maric,

Maric Michaud <maric at aristote.info> writes:
> So, writing C in python, which has dictionnary as builtin type,
> should be considered "more elegant" ?

IMO that's a bit harsh.

> You are comparing apples with lemons, there is no such a difference
> between list index access and dictionnary key access in Python.
[...]
> If you know in advance the number and names of users, what prevent
> you to initialize completelly the target dictionnary ?
>
> The following code compare the same algorithm, once with list and
> the second time with dict :
[...]
> The result is pretty close now :
>
> maric at redflag1 17:04:36:~$ ./test.py
> with list 1.40726399422
> with dict 1.63094091415
>
> So why use list where the obvious and natural data structure is a
> dictionnary ?

I'd never argue that using a dictionary is the obvious and natural
data structure for this case. But is it the best? Honestly, as your
very nice example shows, we have two solutions that are equally fast,
equally complex to code and equally robust, but one needs
approximately the double amount of memory compared to the other. So,
as much as i like dictionaries, what's the gain you get from using it
in this corner case?

Yours,
Karsten



More information about the Python-list mailing list