title: Trying to implement breadth first search from text file in python
body: <p>So I was able to implement breadth first search like this. But Now I am trying to implement breadth first search from a text file that looks like this.</p>
  <p>Textfile:</p>
  <pre><code>1,1
  1,1
  4,1
  4,5
  5,1
  </code></pre>
  <p>This is the code:</p>
  <pre><code>from collections import defaultdict
  
  class Graph:
  def __init__(self): 
      self.graph = defaultdict(list) 
  def addEdge(self,u,v):
      self.graph[u].append(v)
  def BFS(self, s):
      visited = [False] * (max(self.graph) + 1)
      queue = []
      queue.append(s)
      visited[s] = True
      while queue:       
          s = queue.pop(0)
          print (s, end = &quot; &quot;)         
          for i in self.graph[s]:
              if visited[i] == False:
                  queue.append(i)
                  visited[i] = True
  g = Graph()
  g.addEdge(0, 1)
  g.addEdge(0, 2)
  g.addEdge(1, 2)
  g.addEdge(2, 0)
  g.addEdge(2, 3)
  g.addEdge(3, 3)
  </code></pre>
  <p>Output: 2 0 3 1</p>
  <p>This is how I adjusted the text file, but i still cant figure out how to implement it:</p>
  <pre><code>data = open(&quot;ajd.txt&quot;, &quot;r&quot;)
  list_of_lists = []
  for line in data.readlines():
      stripped_line = line.strip('\n')
      line_list = list(map(int, stripped_line.split(',')))
  
      list_of_lists.append(line_list)
  data.close()
  print(list_of_lists)
  adjLists = list_of_lists
  def convert(a):
      adjList = defaultdict(list)
      for i in range(len(a)):
          for j in range(len(a[I])):
              if a[i][j]== 1:
                  adjList[i].append(j)
      return adjList
  </code></pre>
  <p>Output:
  [[1, 1], [1, 1], [4, 1], [4, 5], [5, 1]]</p>