Skip to content

Commit

Permalink
Adjust idiom list( stuff ) where unnecessary--mostly due to 2to3,
Browse files Browse the repository at this point in the history
but also replacing it with sorted( stuff ) when a sort is done immediately.
addresses networkx#560
  • Loading branch information
dschult committed Jun 19, 2011
1 parent 97f50e3 commit 7df1c4b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
6 changes: 2 additions & 4 deletions networkx/algorithms/isomorphism/isomorphvf2.py
Expand Up @@ -270,10 +270,8 @@ def is_isomorphic(self):
if self.G1.order() != self.G2.order(): return False

# Check local properties
d1=list(self.G1.degree().values())
d1.sort()
d2=list(self.G2.degree().values())
d2.sort()
d1=sorted(self.G1.degree().values())
d2=sorted(self.G2.degree().values())
if d1 != d2: return False

try:
Expand Down
3 changes: 1 addition & 2 deletions networkx/algorithms/isomorphism/tests/test_isomorphvf2.py
Expand Up @@ -34,8 +34,7 @@ def test_graph(self):
gm = vf2.GraphMatcher(g1,g2)
assert_true(gm.is_isomorphic())

mapping = list(gm.mapping.items())
mapping.sort()
mapping = sorted(gm.mapping.items())
isomap = [('a', 1), ('b', 6), ('c', 3), ('d', 8),
('g', 2), ('h', 5), ('i', 4), ('j', 7)]
assert_true(mapping==isomap)
Expand Down
6 changes: 3 additions & 3 deletions networkx/classes/graph.py
Expand Up @@ -972,7 +972,7 @@ def neighbors(self, n):
"""
try:
return list(self.adj[n].keys())
return list(self.adj[n])
except KeyError:
raise NetworkXError("The node %s is not in the graph."%(n,))

Expand Down Expand Up @@ -1713,7 +1713,7 @@ def add_path(self, nodes, **attr):
"""
nlist = list(nodes)
edges=list(zip(nlist[:-1],nlist[1:]))
edges=zip(nlist[:-1],nlist[1:])
self.add_edges_from(edges, **attr)

def add_cycle(self, nodes, **attr):
Expand All @@ -1739,7 +1739,7 @@ def add_cycle(self, nodes, **attr):
"""
nlist = list(nodes)
edges=list(zip(nlist,nlist[1:]+[nlist[0]]))
edges=zip(nlist,nlist[1:]+[nlist[0]])
self.add_edges_from(edges, **attr)


Expand Down
6 changes: 2 additions & 4 deletions networkx/generators/tests/test_degree_seq.py
Expand Up @@ -195,13 +195,11 @@ def test_invalid2(self):

def test_li_smax():
G = networkx.barabasi_albert_graph(25,1) #Any old graph
Gdegseq = list(G.degree().values()) #degree sequence
Gdegseq.sort(reverse=True)
Gdegseq = sorted(G.degree().values(),reverse=True) #degree sequence
# Tests the 'unconstrained version'
assert_true(not (sum(Gdegseq)%2))
Gmax = networkx.li_smax_graph(Gdegseq)
Gmaxdegseq = list(Gmax.degree().values())
Gmaxdegseq.sort(reverse=True)
Gmaxdegseq = sorted(Gmax.degree().values(),reverse=True)
assert_equal(G.order(),Gmax.order()) #Sanity Check on the nodes
# make sure both graphs have the same degree sequence
assert_equal(Gdegseq,Gmaxdegseq)
Expand Down

0 comments on commit 7df1c4b

Please sign in to comment.