My first Python program -- a lexer

Thomas Mlynarczyk thomas at mlynarczyk-webdesign.de
Tue Nov 11 16:54:28 CET 2008


John Machin schrieb:

> You are getting closer. A better analogy is that using a dict is like
> transporting passengers along an autobahn in an aeroplane or
> helicopter that never leaves the ground.

It is not a bad idea to transport passengers in an airplane, but then 
the airplane should not follow an autobahn, but use the shortest way -- 
at an appropriate altitude. Translated back to Python dicts, this would 
mean that using a dict for my purposes is a good idea, but that I do not 
make use of its full capabilities -- in other words, I should rewrite my 
code -- still using dict but in a better way. Or do you mean that for 10 
kilometers of autobahn, an airplane would be overkill?

Maybe I am a bit biased by my PHP background, but { name: regex, ... } 
looks simpler to me than [ ( name, regex ), ... ], because the former is 
not a nested structure, while the latter would be a 2D-array in PHP.

Suppose I use the dict and I want to access the regex associatetd with 
the token named "tokenname" (that is, no iteration, but a single 
access). I could simple write tokendict["tokenname"]. But with the list 
of tuples, I can't think of an equally easy way to do that. But then, as 
a beginner, I might be underestimating Python.

Greetings,
Thomas

-- 
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)



More information about the Python-list mailing list