Re: Making things more functional in Python

2005-03-04 Thread Dave Benjamin
On Sat, 2005-03-05 at 00:00 -0700, Dave Benjamin wrote: > On Fri, 2005-03-04 at 08:36 -0800, gf gf wrote: > > Is there a better, more FP style, more Pythonic way to > > write this: > > > > def compute_vectors(samples, dset): > > vectors = {} > > for d in dset: > > vectors[d] =

Re: Making things more functional in Python

2005-03-04 Thread Dave Benjamin
On Fri, 2005-03-04 at 08:36 -0800, gf gf wrote: > Is there a better, more FP style, more Pythonic way to > write this: > > def compute_vectors(samples, dset): > vectors = {} > for d in dset: > vectors[d] = [sample.get_val(d) for sample in > samples] > return vectors

Re: Making things more functional in Python

2005-03-04 Thread Steve Holden
Michael Hoffman wrote: Steve Holden wrote: return dict([(d, sample.getval(d)) for d in dset for sample in samples]) That won't do what the original code does. This sets dict[d] to samples[-1].getval(d) instead of [sample.getval(d) for sample in samples]. My bad, I didn;t look closely enbough to se

Re: Making things more functional in Python

2005-03-04 Thread Michael Hoffman
Steve Holden wrote: return dict([(d, sample.getval(d)) for d in dset for sample in samples]) That won't do what the original code does. This sets dict[d] to samples[-1].getval(d) instead of [sample.getval(d) for sample in samples]. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/pytho

Re: Making things more functional in Python

2005-03-04 Thread Bill Mill
On Fri, 4 Mar 2005 08:36:49 -0800 (PST), gf gf <[EMAIL PROTECTED]> wrote: > Is there a better, more FP style, more Pythonic way to > write this: > > def compute_vectors(samples, dset): > vectors = {} > for d in dset: > vectors[d] = [sample.get_val(d) for sample in >

Re: Making things more functional in Python

2005-03-04 Thread Steve Holden
gf gf wrote: Is there a better, more FP style, more Pythonic way to write this: def compute_vectors(samples, dset): vectors = {} for d in dset: vectors[d] = [sample.get_val(d) for sample in samples] return vectors Namely, I'd like to get rid of the initilizat

Re: Making things more functional in Python

2005-03-04 Thread Michael Hoffman
gf gf wrote: Is there a better, more FP style, more Pythonic way to write this: def compute_vectors(samples, dset): vectors = {} for d in dset: vectors[d] = [sample.get_val(d) for sample in samples] return vectors Namely, I'd like to get rid of the initilizat

Making things more functional in Python

2005-03-04 Thread gf gf
Is there a better, more FP style, more Pythonic way to write this: def compute_vectors(samples, dset): vectors = {} for d in dset: vectors[d] = [sample.get_val(d) for sample in samples] return vectors Namely, I'd like to get rid of the initilization (vector