When passing functions as args, how to pass extra args for passed function?

Christos TZOTZIOY Georgiou tzot at sil-tec.gr
Wed Sep 17 00:27:35 CEST 2003

On Tue, 16 Sep 2003 17:08:53 -0400 (EDT), rumours say that
python at sarcastic-horse.com might have written:

>When I pass a function as an arg, like for map(...), how do I pass args to
>use for that function?
>If I have a function like this:
>def pretty_format(f, fmt='%0.3f'):
>    return fmt % f
>I want to use it with map() like this:
>formatted = map(pretty_format, unformatted_list)
>#exept I want fmt='%4.5f' !!!
>I need to figure out how to pass a non-default value for fmt.  How do I do

I believe this is what you want:

formatted = map(pretty_format, unformatted_list,
    ['%4.5f'] * len(unformatted_list))
TZOTZIOY, I speak England very best,
Microsoft Security Alert: the Matrix began as open source.

More information about the Python-list mailing list