[Python-ideas] generic Ref class

Aaron Brady castironpi at comcast.net
Sat Jan 12 21:03:44 CET 2008


For iteration and pass-by-reference semantics:

	class Ref:
		def __init__( self, val):
			self.val= val

To modify list during iteration:

	def refs( iterable ):
		return [ Ref( x ) for x in iterable ]

Then:

	for x in refs( listA ):
		x.val+= 1

Better than:

	for i, x in enumerate( listA ):
		listA[i]= x+ 1

Example is naturally trivial; imagine.  No bloat here; get over it.



More information about the Python-ideas mailing list