List comprehension - NameError: name '_[1]' is not defined ?

mario ruggier mario.ruggier at
Thu Jan 15 17:09:53 CET 2009

The listcomps exploration above was primarily an attempt
(unsuccessful) to make this piece of code go a little faster:

s = " text %(item)s text "
acc = []
for value in iterator:
    some_dict["item"] = value
    acc.append(s % evaluator)

The item=value pair is essentially a loop variable, and the evaluator
(something like the gie instance above) uses it via the updated

Is there any way to express the above as a list comp or so? Any ideas
how it might be made to go faster?


More information about the Python-list mailing list