Skip to content

Instantly share code, notes, and snippets.

@jacquerie
Last active August 29, 2015 14:23
Show Gist options
  • Save jacquerie/eb1329cdf3b52e81c982 to your computer and use it in GitHub Desktop.
Save jacquerie/eb1329cdf3b52e81c982 to your computer and use it in GitHub Desktop.
Explicit assignment and `+=` yield different results if the index produces side effects
#!/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