Last active
August 29, 2015 14:23
-
-
Save jacquerie/eb1329cdf3b52e81c982 to your computer and use it in GitHub Desktop.
Explicit assignment and `+=` yield different results if the index produces side effects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from itertools import count | |
a = [1, 10] | |
b = [1, 10] | |
c1 = count(0).next | |
c2 = count(0).next | |
a[c1()] = a[c1()] + 1 | |
b[c2()] += 1 | |
print a # [1, 2] | |
print b # [2, 10] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment