ericmjl / Network-Analysis-Made-Simple

An introduction to network analysis and applied graph theory using Python and NetworkX
https://ericmjl.github.io/Network-Analysis-Made-Simple/index.html
MIT License
1.04k stars 401 forks source link

TypeError: unhashable type: 'slice' #41

Closed srbdev closed 6 years ago

srbdev commented 6 years ago

In the notebook 2-networkx-basics-instructor.ipynb, the first code cell after the Basic Network Statistics section

# Who are represented in the network?
G.nodes()[0:5]

returns the following error on my Macbook:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-22-3fb6155cc2e4> in <module>()
      1 # Who are represented in the network?
----> 2 G.nodes()[0:5]

~/playspace/pycon2018/Network-Analysis-Made-Simple/network/lib/python3.6/site-packages/networkx/classes/reportviews.py in __getitem__(self, n)
    176 
    177     def __getitem__(self, n):
--> 178         return self._nodes[n]
    179 
    180     # Set methods

TypeError: unhashable type: 'slice'

I can fix the issue with

list(G.nodes())[0:5]

Let me know if this is an actual issue or just something not setup correctly on my end. Thanks!

ericmjl commented 6 years ago

@srbdev thanks for picking that out! Yes, with the new NetworkX API, G.nodes() and G.edges() now return views into the node and edge lists respectively.

A fix will be coming soon :smile:.

ericmjl commented 6 years ago

Bug has been fixed in Notebook 2.