title: Networkx with errors from adding nodes and edges
body: <p>This is a simple python program to generate a network graph.  Everything was fine when I placed the data inside the program but when I decided to place the data in two input files, things started to get interesting.  There are two input files: nodes (or vertices) and edges.  When I read the nodes information from the input files called  'Step3-Vertices.txt', it did not give any error but additional information were added to the nodes which I did not supply.  Here is a list of additional information :
   <code>'[', '{', "'", '0', '2', ',', ' ', '6', '8', 'W', '}', '.', '1', '5', '3', '7', '4', 'O', 'X', 'D', ']', '\n'</code></p>
  
  <p>I then read in the 2nd file called 'Step3-Edges.txt', this time I got a list of error messages which I could not comprehend.</p>
  
  <p>ERROR MESSAGES - NETWORKX FAILED WHEN EDGES INFORMATION ARE ADDED FROM FILE :  </p>
  
  <pre><code>Traceback (most recent call last):
  File "step4_test1.py", line 30, in &lt;module&gt;
  G.add_edges_from(data_edges)
  File "/home/desmond/anaconda3/lib/python3.6/site-packages/networkx/classes/graph.py", line 934, in add_edges_from
  "Edge tuple %s must be a 2-tuple or 3-tuple." % (e,))
  networkx.exception.NetworkXError: Edge tuple [ must be a 2-tuple or 3-tuple.
  </code></pre>
  
  <p>Could someone help me please?</p>
  
  <p>Here is my program:</p>
  
  <pre><code>""" THIS PROGRAM WORKS PROPERLY WHEN DATA ARE PASSED TO LOCAL VARIABLES CALLED "nodes" and "edges".  THE EXACT DATA ARE ALSO STORED IN TWO FILES: "nodes" in 'Step3-Vertices.txt' and "edges" in 'Step3-Edges.txt'.  PROBLEMS STARTED WHEN NODES AND EDGES ARE READ FROM BOTH FILES.  FIRST, RUN THIS PROGRAM AND IT SHOULD GENERATE A GRAPH.  THEN REPLACE THE "nodes" with "data_nodes" in "G.add_nodes_from" AND THIS WILL GENERATE UNEXPECTED ADDITIONAL NODES WHICH ARE NOT SUPPOSED TO BE THERE.  NEXT, REPLACE THE "edges" with "data_edges" in "G.add_nodes_from" AND ERROR MESSAGES ARE DISPLAYED."""  
  
  
  import networkx as nx
  import matplotlib.pyplot as plt
  
  
  
  """ READ NODES INFORMATION FROM FILE """
  
  with open('Step3-Vertices.txt', encoding='utf-8') as data_file:
      data_nodes = data_file.read()
  
  print(data_nodes)
  
  """ READ EDGESS INFORMATION FROM FILE """
  
  
  with open('Step3-Edges.txt', encoding='utf-8') as data_file:
      data_edges = data_file.read()
  
  print(data_edges)
  
  
  G=nx.Graph()
  
  """  PASS NODES INFORMATION TO A VARIABLE CALLED 'nodes'   """
  
  nodes = ['0000000002', '0000000101', '0000000111', '0000000200', '0000000502', '0000000600', '0000001000', '0000001001', '0000001069', '0000001253', '0000001462', '0000003013', '0000003200', '0000004100', '0000004305', '0000005100', '0000005460', '0000006600', '0000010021', '0000010101', '0000010200', '0000010314', '0000012000', '0000012151', '0000012600', '0000015201', '0000016100', '0000017002', '0000020002', '0000020050', '0000020100', '0000021001', '0000022044', '0000022100']
  
  
  """ PASS EDGES INFORMATION TO A VARIABLE CALLED 'edges'   """
  
  edges = [{'0000000002', '6080022W'}, {'80.015.012.210', '0000000002'}, {'80.015.012.210', '0000000502'}, {'0000012000', '0000000502'},{'0000000101', '012.105.123.127'}, {'0000000111', '2442032O'}, {'105.103.02.110', '0000000111'}, {'0604054X', '0000000200'}, {'100.001.008.002', '0000000200'}, {'0000000502', '1002567D'}, {'208.08.032.1', '0000000502'}]
  
  """THIS IS WHERE YOU ADD DATA TO THE NODES AND EDGES, BY DEFAULT, LOCAL VARIABLES ARE USED. TO ADD DATA FROM THE INPUT FILES - replace 'nodes' with 'data_nodes' and replace 'edges' with 'data_edges'   """
  
  
  
  
  G.add_nodes_from(nodes)
  G.add_edges_from(edges)
  
  print("Nodes of graph: ")
  print(G.nodes())
  
  
  print("Edges of graph: ")
  print(G.edges())
  
  ###  DRAW A GRAPH  ###
  
  nx.draw(G)
  plt.savefig("test1.png") # save as png
  plt.show() # display
  </code></pre>