File size: 745 Bytes
9be4956 b948647 9be4956 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from pandas import DataFrame
class Cities:
def __init__(self ,path="/home/user/app/database/background/citySet_with_states.txt") -> None:
self.path = path
self.load_data()
print("Cities loaded.")
def load_data(self):
cityStateMapping = open(self.path, "r").read().strip().split("\n")
self.data = {}
for unit in cityStateMapping:
city, state = unit.split("\t")
if state not in self.data:
self.data[state] = [city]
else:
self.data[state].append(city)
def run(self, state) -> dict:
if state not in self.data:
return ValueError("Invalid State")
else:
return self.data[state] |