Skip to content

Instantly share code, notes, and snippets.

@ctb
Last active May 23, 2020 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctb/38e70e1cf2ff4ad1c0add1ec6a24cd39 to your computer and use it in GitHub Desktop.
Save ctb/38e70e1cf2ff4ad1c0add1ec6a24cd39 to your computer and use it in GitHub Desktop.
wth?
# in a Jupyter notebook, after %pylab inline
# so - not a Python bug, but a pylab/numpy thing
c = collections.Counter()
c['a'] = 5
c['b'] = 3
print('XXX:', sum(c.values()))
print('YYY:', sum([ x for x in c.values() ]))
# gives:
# XXX: dict_values([5, 3])
# YYY: 8
@rougier
Copy link

rougier commented May 23, 2020

Works as expected with Python 3.7.6

@ctb
Copy link
Author

ctb commented May 23, 2020

huh! so it does in my conda install. I feel like I tested this in a few different versions... argh

@ctb
Copy link
Author

ctb commented May 23, 2020

argh now I can't replicate it :). had a whole discussion on lab slack about this.

@ctb
Copy link
Author

ctb commented May 23, 2020

others replicated it.

etc.

maybe it was just fixed in a more recent version.

@ctb
Copy link
Author

ctb commented May 23, 2020

wait no, found the notebook I first encountered it in, using same conda environment (py 3.7.6). maybe an import order thing? ...ah-hah.

%pylab inline

is causing it.

@rougier
Copy link

rougier commented May 23, 2020

Nice catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment