Compact syntax for 0-matrix?
Kirby Urner
urner at alumni.princeton.edu
Tue May 30 14:30:43 EDT 2000
kajiyama at grad.sccs.chukyo-u.ac.jp (Tamito Kajiyama) wrote:
>Kirby Urner <urner at alumni.princeton.edu> writes:
>>
>> Here's another function I like OK:
>>
>> def zeromatrix(n,m):
>> output = []
>> for i in range(n): output.append([0]*m)
>> return output
>
>Or, more shortly,
>
> def zeromatrix(m, n):
> return map(lambda x: [0]*x, [n]*m)
>
>It seems more time-consuming, though ;)
>
>--
>KAJIYAMA, Tamito <kajiyama at grad.sccs.chukyo-u.ac.jp>
Yes, that's very compact, really tests one's understanding
of lambda.
I'm thinking this "zeromatrix" exercise might be a good
one for Python learners -- certainly it has been helpful
to me.
Kirby
More information about the Python-list
mailing list