Guest User

Untitled

a guest
Nov 7th, 2017
8,724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2.  
  3. with open ("nba_stats.html", "r") as myfile:
  4.     html_doc=myfile.read()
  5.    
  6. soup = BeautifulSoup(html_doc, 'html.parser')
  7.  
  8. myNames = soup.find_all(class_ =  "players-list__name")
  9.  
  10. players = []
  11. for name in myNames:
  12.     if "," in name.string:
  13.         name = name.string.split(", ")[::-1]
  14.     else:
  15.         name = name.string.split(" ")
  16.     players.append(tuple(name))
  17.  
  18. graph = {tuple(player) : set() for player in players}    
  19.  
  20. N = len(players)
  21.  
  22. for player in graph:
  23.     for i in range(N):
  24.         other = players[i]
  25.         if other == player:
  26.             continue
  27.         if player[-1] == other[0]:
  28.             graph[player].add(other)
  29.  
  30.        
  31. def bfs_paths(graph, start):
  32.     queue = [(start, [start])]
  33.     path, next = [], []
  34.     while queue:
  35.         (vertex, path) = queue.pop(0)
  36.         for next in graph[vertex] - set(path):
  37.             queue.append((next, path + [next]))
  38.     return path
  39.  
  40. max_so_far = []
  41. for player in graph:
  42.     p = bfs_paths(graph, player)
  43.     if len(p) > len(max_so_far):
  44.         max_so_far = p
  45.  
  46. print(max_so_far)
Advertisement
Add Comment
Please, Sign In to add comment