Ka-Ping Yee wrote: [...] > > # pretend lists are implemented in Python and 'self' is a list > > def shift(self): > > item = self[0] > > del self[:1] > > return item [...] Guido van Rossum: > You can do this using list.pop(0). I don't think the name "shift" is very > intuitive (smells of sh and Perl :-). Do we need a new function? I think no. But what about this one?: # pretend self and dict are dictionaries: def supplement(self, dict): for k, v in dict.items(): if not self.data.has_key(k): self.data[k] = v Note the similarities to {}.update(dict), but update replaces existing entries in self, which is sometimes not desired. I know, that supplement can also simulated with: tmp = dict.copy() tmp.update(self) self.data = d But this is stll a little ugly. IMO a builtin method to supplement (complete?) a dictionary with default values from another dictionary would sometimes be a useful tool. Regards, Peter -- Peter Funk, Oldenburger Str.86, D-27777 Ganderkesee, Germany, Fax:+49 4222950260 office: +49 421 20419-0 (ArtCom GmbH, Grazer Str.8, D-28359 Bremen)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4