Using dictionary to hold regex patterns?

John Machin sjmachin at lexicon.net
Mon Nov 24 16:38:15 EST 2008


On Nov 25, 4:38 am, Thomas Mlynarczyk <tho... at mlynarczyk-webdesign.de>
wrote:
> John Machin schrieb:
>
> > Rephrasing for clarity: Don't use a data structure that is more
> > complicated than that indicated by your requirements.
>
> Could you please define "complicated" in this context? In terms of
> characters to type and reading, the dict is surely simpler. But I
> suppose that under the hood, it is "less work" for Python to deal with a
> list of tuples than a dict?

The two extra parentheses per item are a trivial cosmetic factor only
when the data is hard-coded i.e. don't exist if the data is read from
a file i.e nothing to do with "complicated". The amount of work done
by Python under the hood is relevant only to a speed/memory
requirement. No, "complicated" is more related to unused features. In
the case of using an aeroplane to transport 3 passengers 10 km along
the autobahn, you aren't using the radar, wheel-retractability, wings,
pressurised cabin, etc. In your original notion of using a dict in
your lexer, you weren't using the mapping functionality of a dict at
all. In both cases you have perplexed bystanders asking "Why use a
plane/dict when a car/list will do the job?".

>
> > Judging which of two structures is "simpler" should not be independent
> > of those requirements. I don't see a role for intuition in this
> > process.
>
> Maybe I should have said "upon first sight" / "judging from the outer
> appearance" instead of "intuition".

I don't see a role for "upon first sight" or "judging from the outer
appearance" either.




More information about the Python-list mailing list