summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJarrod Millman <jarrod.millman@gmail.com>2019-12-30 23:22:28 -0800
committerJarrod Millman <jarrod.millman@gmail.com>2020-01-01 14:17:42 -0800
commit11954636c80e899c2cd6ea2dbafd628aa8662811 (patch)
treef391e91bd8ff4fddd7f62f57f3c9565d27ef33ed /examples
parent1bbcc512ae492e7467140100d1be137bef9410d6 (diff)
downloadnetworkx-11954636c80e899c2cd6ea2dbafd628aa8662811.tar.gz
Upgrade to Py36 syntax
$ find examples -name \*.py -exec pyupgrade --py36-plus {} \;
Diffstat (limited to 'examples')
-rw-r--r--examples/drawing/plot_chess_masters.py2
-rw-r--r--examples/drawing/plot_knuth_miles.py2
-rw-r--r--examples/drawing/plot_lanl_routes.py2
-rw-r--r--examples/graph/plot_roget.py2
-rw-r--r--examples/graph/plot_words.py2
-rw-r--r--examples/subclass/plot_antigraph.py15
6 files changed, 12 insertions, 13 deletions
diff --git a/examples/drawing/plot_chess_masters.py b/examples/drawing/plot_chess_masters.py
index ca2f3ef5..4bb877c1 100644
--- a/examples/drawing/plot_chess_masters.py
+++ b/examples/drawing/plot_chess_masters.py
@@ -79,7 +79,7 @@ if len(Gcc) > 1:
print(Gcc[1].nodes())
# find all games with B97 opening (as described in ECO)
-openings = set([game_info["ECO"] for (white, black, game_info) in G.edges(data=True)])
+openings = {game_info["ECO"] for (white, black, game_info) in G.edges(data=True)}
print(f"\nFrom a total of {len(openings)} different openings,")
print("the following games used the Sicilian opening")
print('with the Najdorff 7...Qb6 "Poisoned Pawn" variation.\n')
diff --git a/examples/drawing/plot_knuth_miles.py b/examples/drawing/plot_knuth_miles.py
index e4b016c9..1a745f19 100644
--- a/examples/drawing/plot_knuth_miles.py
+++ b/examples/drawing/plot_knuth_miles.py
@@ -43,7 +43,7 @@ def miles_graph():
if line.startswith("*"): # skip comments
continue
- numfind = re.compile("^\d+")
+ numfind = re.compile(r"^\d+")
if numfind.match(line): # this line is distances
dist = line.split()
diff --git a/examples/drawing/plot_lanl_routes.py b/examples/drawing/plot_lanl_routes.py
index 07b9e5d0..bb99456a 100644
--- a/examples/drawing/plot_lanl_routes.py
+++ b/examples/drawing/plot_lanl_routes.py
@@ -23,7 +23,7 @@ def lanl_graph():
"""
try:
fh = open("lanl_routes.edgelist", "r")
- except IOError:
+ except OSError:
print("lanl.edges not found")
raise
diff --git a/examples/graph/plot_roget.py b/examples/graph/plot_roget.py
index 19ff547b..4f8df1a4 100644
--- a/examples/graph/plot_roget.py
+++ b/examples/graph/plot_roget.py
@@ -50,7 +50,7 @@ def roget_graph():
(headname, tails) = line.split(":")
# head
- numfind = re.compile("^\d+") # re to find the number of this word
+ numfind = re.compile(r"^\d+") # re to find the number of this word
head = numfind.findall(headname)[0] # get the number
G.add_node(head)
diff --git a/examples/graph/plot_words.py b/examples/graph/plot_words.py
index bfe3eb50..ccaaebb7 100644
--- a/examples/graph/plot_words.py
+++ b/examples/graph/plot_words.py
@@ -24,7 +24,7 @@ import networkx as nx
def generate_graph(words):
G = nx.Graph(name="words")
- lookup = dict((c, lowercase.index(c)) for c in lowercase)
+ lookup = {c: lowercase.index(c) for c in lowercase}
def edit_distance_one(word):
for i in range(len(word)):
diff --git a/examples/subclass/plot_antigraph.py b/examples/subclass/plot_antigraph.py
index d49943c1..3543da36 100644
--- a/examples/subclass/plot_antigraph.py
+++ b/examples/subclass/plot_antigraph.py
@@ -54,10 +54,9 @@ class AntiGraph(nx.Graph):
The adjacency dictionary for nodes connected to n.
"""
- return dict(
- (node, self.all_edge_dict)
- for node in set(self.adj) - set(self.adj[n]) - set([n])
- )
+ return {
+ node: self.all_edge_dict for node in set(self.adj) - set(self.adj[n]) - {n}
+ }
def neighbors(self, n):
"""Return an iterator over all neighbors of node n in the
@@ -65,7 +64,7 @@ class AntiGraph(nx.Graph):
"""
try:
- return iter(set(self.adj) - set(self.adj[n]) - set([n]))
+ return iter(set(self.adj) - set(self.adj[n]) - {n})
except KeyError:
raise NetworkXError(f"The node {n} is not in the graph.")
@@ -109,7 +108,7 @@ class AntiGraph(nx.Graph):
n,
{
v: self.all_edge_dict
- for v in set(self.adj) - set(self.adj[n]) - set([n])
+ for v in set(self.adj) - set(self.adj[n]) - {n}
},
)
for n in self.nodes()
@@ -123,7 +122,7 @@ class AntiGraph(nx.Graph):
n,
{
v: self.all_edge_dict
- for v in set(self.nodes()) - set(self.adj[n]) - set([n])
+ for v in set(self.nodes()) - set(self.adj[n]) - {n}
},
)
for n in self.nbunch_iter(nbunch)
@@ -153,7 +152,7 @@ class AntiGraph(nx.Graph):
"""
for n in self.adj:
- yield (n, set(self.adj) - set(self.adj[n]) - set([n]))
+ yield (n, set(self.adj) - set(self.adj[n]) - {n})
# Build several pairs of graphs, a regular graph