While debugging a network algorithm in Python 2.6.2, I encountered some strange behavior and was wondering whether it has to do with some sort of code optimization that Python does behind the scenes.
************
After initialization: defaultdict(<type 'set'>, {1: set([1])})
Popping and updating in two steps: defaultdict(<type 'set'>, {1: set([1])})
************
After initialization: defaultdict(<type 'set'>, {1: set([1])})
Popping and updating in one step: defaultdict(<type 'set'>, {})
import collections
print '************'
x = collections.defaultdict(set)
x[1].update([1])
print 'After initialization: %s' % x
items = x.pop(1)
x[1].update(items)
print 'Popping and updating in two steps: %s' % x
print '************'
y = collections.defaultdict(set)
y[1].update([1])
print 'After initialization: %s' % y
y[1].update(y.pop(1))
print 'Popping and updating in one step: %s' % y
inOneStepVSTwoSteps.py
Description: Binary data
_______________________________________________ Python-Dev mailing list [email protected] http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
