hsaest's picture
Upload folder using huggingface_hub
9be4956 verified
raw
history blame
733 Bytes
from pandas import DataFrame
class Cities:
def __init__(self ,path="../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]