Emulating Pascal input
Kragen Sitaker
kragen at pobox.com
Sat May 25 14:05:39 EDT 2002
Steven Majewski <sdm7g at Virginia.EDU> writes:
> On 25 May 2002, Giles Brown wrote:
> > result = []
> > for field, converter in zip(fields, converters):
> > result.append(converter(field))
> > return result
>
> The above is done better as:
> return map(converters, fields)
In what version of Python?
In 2.1.1 I get an error trying that:
>>> map([str, str, lambda x: x * 3], [1, 2, 3])
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: object of type 'list' is not callable
I guess you meant map(lambda x, y: x(y), converters, fields), and I
agree that would be better. I'm quite surprised to find that lambda
x, y: x(y) doesn't have a name in the operator module; 'apply' is
almost right, but not quite.
The listcomp equivalent would be
[x(y) for x, y in zip(converters, fields)]
and I think that's even better.
More information about the Python-list
mailing list