[Python-checkins] r59504 - in python/trunk: Doc/library/collections.rst Lib/collections.py

raymond.hettinger python-checkins at python.org
Fri Dec 14 20:19:59 CET 2007


Author: raymond.hettinger
Date: Fri Dec 14 20:19:59 2007
New Revision: 59504
Modified:
 python/trunk/Doc/library/collections.rst
 python/trunk/Lib/collections.py
Log:
Faster and simpler _replace() method
Modified: python/trunk/Doc/library/collections.rst
==============================================================================
--- python/trunk/Doc/library/collections.rst	(original)
+++ python/trunk/Doc/library/collections.rst	Fri Dec 14 20:19:59 2007
@@ -402,7 +402,7 @@
 
 def _replace(self, **kwds):
 'Return a new Point object replacing specified fields with new values'
- return Point(**dict(zip(('x', 'y'), self), **kwds))
+ return Point(*map(kwds.get, ('x', 'y'), self))
 
 x = property(itemgetter(0))
 y = property(itemgetter(1))
Modified: python/trunk/Lib/collections.py
==============================================================================
--- python/trunk/Lib/collections.py	(original)
+++ python/trunk/Lib/collections.py	Fri Dec 14 20:19:59 2007
@@ -71,7 +71,7 @@
 return dict(zip(%(field_names)r, self)) \n
 def _replace(self, **kwds):
 'Return a new %(typename)s object replacing specified fields with new values'
- return %(typename)s(**dict(zip(%(field_names)r, self), **kwds)) \n\n''' % locals()
+ return %(typename)s(*map(kwds.get, %(field_names)r, self)) \n\n''' % locals()
 for i, name in enumerate(field_names):
 template += ' %s = property(itemgetter(%d))\n' % (name, i)
 if verbose:


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /