Making things more functional in Python

gf gf unknownsoldier93 at yahoo.com
Fri Mar 4 11:36:49 EST 2005


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
(vectors = {}) and also the loop  Yet, I'd hate to put
an assignment into Python's FP list comprehensions.

Ideally, I'd like something like this:
vectors.dict_add({d:result}) for [sample.get_val(d)
for sample in samples for d in dset].  

Is there anything like that?  Am I missing the
picture?

Thanks.

PS If possible, please cc me on all responses, thanks.


	
		
__________________________________ 
Celebrate Yahoo!'s 10th Birthday! 
Yahoo! Netrospective: 100 Moments of the Web 
http://birthday.yahoo.com/netrospective/



More information about the Python-list mailing list