Last active
September 11, 2021 04:01
-
-
Save SeungheonOh/55a7e31dde6d0a7ed7da9c75eefa0693 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
import csv | |
@dataclass | |
class College: | |
name: str #INSTNM | |
address: str #ACCREDAGENCY | |
zip_code: int #ZIP | |
website: str #INSTURL | |
tui_in: int #TUITIONFEE_IN | |
tui_out: int #TUITIONFEE_OUT | |
city: str #CITY | |
adm_rate: int #ADM_RATE | |
sat_avg: int #SAT_AVG | |
longitude: float #LONGITUDE | |
latitude: float #LATITUDE | |
def __str__(self): | |
return '''name: {}\naddress: {} \nzip_code: {} \nwebsite: {}\ntui_in: {} \ntui_out: {} \ncity: {} \nadm_rate: {} \nsat_avg: {} \nlongitude: {} \nlatitude: {} '''.format(self.name, self.address, self.zip_code, self.website, self.tui_in, self.tui_out, self.city, self.adm_rate, self.sat_avg, self.longitude, self.latitude) | |
pint = lambda x: int(x) if x.isdecimal() and not x == "-" else -1 | |
pfloat = lambda x: float(x) if not x == "-" else -1 | |
dicToStruct = lambda d: College(d["INSTNM"], d["ACCREDAGENCY"], pint(d["ZIP"]), d["INSTURL"], pint(d["TUITIONFEE_IN"]), pint(d["TUITIONFEE_OUT"]), d["CITY"], pfloat(d["ADM_RATE"]), pint(d["SAT_AVG"]), pfloat(d["LONGITUDE"]), pfloat(d["LATITUDE"])) | |
load = lambda a: list(map(dicToStruct ,csv.DictReader(open(a)))) | |
contains = lambda whole, part: part in whole | |
search = lambda l, n: list(filter(lambda c: contains(c.name, n), l)) | |
choice = lambda l: list(map(lambda c: print("[{}] {}".format(l.index(c), c.name)), l)) | |
loop = (lambda cs: # all colleges | |
(lambda _: loop(cs)) # recursive loop! | |
(print( | |
(lambda sc: # searched | |
(lambda found: | |
found() if len(sc) > 0 else "result not found" | |
)(lambda: | |
(lambda _: # index input | |
(lambda i: | |
str(sc[i]) + "\n" if 0 <= i < len(sc) else "invalid index" | |
) (pint(input("index[{}-{}]? ".format(0, len(sc))))) | |
)(choice(sc)) | |
) | |
)(search(cs, input("name? ")))) | |
)) | |
loop((lambda _: load("university-data.csv"))(print("loading..."))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment