functional programming with map()
David Eppstein
eppstein at ics.uci.edu
Tue Feb 26 13:31:19 EST 2002
In article <slrn.pl.a7lbtu.3vs69hb.imbaczek at baczek.net.invalid>,
Marek "Baczek" Baczyski <imbaczek at poczta.fm> wrote:
> Pete Shinners wyprodukowa½[ao]?:
>
> > Donnal Walter wrote:
> >> But what is the functional equvalent of:
> >>
> >> for x in items:
> >> x.f()
> >
> > if all "items" are the same class, you could get away with this,
> >
> > map(class_of_x.f, items)
>
> map(type(x).f, items) solves the problem.
x looks like an unbound variable to me. map(type(items[0]).f, items) is
close but doesn't work for generators or mixed lists. If you really insist
on map, it looks like the right thing is map(lambda x: x.f(), items).
--
David Eppstein UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/
More information about the Python-list
mailing list