Re: dict.updated
Rick Morrison wrote: > >>> [updated(d, {'c':3}) for d in [{'a':1, 'b':2}, {'x':10, 'y':'11'}]] > [{'a': 1, 'c': 3, 'b': 2}, {'y': '11', 'x': 10, 'c': 3}] I don't really understand the use of this. Can you give a less toy example? I'd probably just do dicts = [{'a':1, 'b':2}, {'x':10, 'y':'11'}] for d in dicts: d.update({'c':3}) This isn't really more typing or any clumsier IMO, so I can't see why you'd want to use list comprehensions in this case. -- http://mail.python.org/mailman/listinfo/python-list
Re: lambda
Antoon Pardon wrote: > So if I have a call with an expression that takes more than > one line, I should assign the expression to a variable and > use the variable in the call? Yes, that's sometimes a good practice and can clarify the call. > But wait if I do that, people will tell me how bad that it > is, because it will keep a reference to the value which > will prevent the garbage collector from harvesting this > memory. Nobody will tell you that it's bad. Python was never about super performance, but about readability. Besides, using such temporaries won't consume much memory (relatively). > Besides python allows more than one statement on the same line. But it's discouraged in general. -- http://mail.python.org/mailman/listinfo/python-list
Re: dynamically inserting function into an object
# class Cell(object): # def __init__(self, initialvalue = 0): #self._func = lambda x: x #self.__value = initialvalue # # def setvalue (self, newvalue): # self.__value = self._func(newvalue) # # def getvalue (self): # return self.__value # # def delvalue (self): # del self.__value # # value = property(getvalue, setvalue, delvalue, "I'm the 'value' property.") # # def curry(self, func, *args): # self._func = lambda x: func(x, *args) -- http://mail.python.org/mailman/listinfo/python-list