AllenDowney / ThinkStats2

Text and supporting code for Think Stats, 2nd Edition
http://allendowney.github.io/ThinkStats2/
GNU General Public License v3.0
4.03k stars 11.31k forks source link

Iteration of dict keys and values fails in panda_demos notebook when running in Python 3 #85

Closed gbremer closed 7 years ago

gbremer commented 7 years ago

In cell 24, an interation over a dictionary's keys and values fails with an attribute exception, that iteritems() is not available.

The code is --

import numpy

for sex, weights in d.iteritems():
    print(sex, numpy.log(weights).mean(), numpy.log(weights).std())

The exception is --

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-24-31c478b07415> in <module>()
      1 import numpy
      2 
----> 3 for sex, weights in d.iteritems():
      4     print(sex, numpy.log(weights).mean(), numpy.log(weights).std())

AttributeError: 'dict' object has no attribute 'iteritems'

This fails with a new install of Anaconda Python 3.6, and succeeds in a new install of Python 2.7.

gbremer commented 7 years ago

Closed with fix merged