Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup
- with open ("nba_stats.html", "r") as myfile:
- html_doc=myfile.read()
- soup = BeautifulSoup(html_doc, 'html.parser')
- myNames = soup.find_all(class_ = "players-list__name")
- players = []
- for name in myNames:
- if "," in name.string:
- name = name.string.split(", ")[::-1]
- else:
- name = name.string.split(" ")
- players.append(tuple(name))
- graph = {tuple(player) : set() for player in players}
- N = len(players)
- for player in graph:
- for i in range(N):
- other = players[i]
- if other == player:
- continue
- if player[-1] == other[0]:
- graph[player].add(other)
- def bfs_paths(graph, start):
- queue = [(start, [start])]
- path, next = [], []
- while queue:
- (vertex, path) = queue.pop(0)
- for next in graph[vertex] - set(path):
- queue.append((next, path + [next]))
- return path
- max_so_far = []
- for player in graph:
- p = bfs_paths(graph, player)
- if len(p) > len(max_so_far):
- max_so_far = p
- print(max_so_far)
Advertisement
Add Comment
Please, Sign In to add comment