-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgraph_practice.py
More file actions
41 lines (35 loc) · 1.05 KB
/
graph_practice.py
File metadata and controls
41 lines (35 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Graph:
def __init__(self, flights):
self.airports = []
self.graph = {}
for depart, destin in flights:
self.addAirport(depart, destin)
# self.addFlights(flight)
def addAirport(self, depart, destin):
if depart not in self.graph:
self.airports.append(depart)
self.graph[depart] = []
if destin not in self.graph:
self.airports.append(destin)
self.graph[depart].append(destin)
def printFlights(self):
for flight in self.graph:
print(flight, ":", self.graph[flight])
print()
# class Airport:
# def __init__(self, airport):
# self.airport = airport
flights = [['Newark, NJ', 'Los Angeles, CA'],
['Miami, FL', 'Los Angeles, CA'],
['Fort Laud, FL', 'Newark, CA'],
['New Orleans, LA', 'JFK, NY'],
['JFK, NY', 'Dallas, TX'],
['Minnestoa, MI', 'Newark, NJ'],
['Houston, TX', 'Fort Laud, FL'],
['Houston, TX', 'Miami, FL'],
['Las Vegas, NV', 'San Fran, CA'],
['San Fran, CA', 'Miami, FL']]
myFlights = Graph(flights)
# print(myFlights.graph)
myFlights.printFlights()
# ------------------------------------