5 Commits

Author SHA1 Message Date
Kira aca90d8335 Small refactor to make code more clean. 2026-01-01 17:31:20 +01:00
Kira 2176c244ea Remove input country from output. Accept lower case country codes. 2026-01-01 17:31:08 +01:00
Kira 0311c41422 Fix panic when country code is not in db. 2026-01-01 17:30:57 +01:00
Kira d5193a17ec Initial commit, hopefully everything is fine :3 2026-01-01 17:30:48 +01:00
Kira 4bc1069091 Initial commit 2026-01-01 17:29:28 +01:00
+10 -5
View File
@@ -182,7 +182,7 @@ NEAR_COUNTRIES = {
"YE": ['OM', 'SA'], "YE": ['OM', 'SA'],
"ZA": ['BW', 'LS', 'MZ', 'NA', 'SZ', 'ZW'], "ZA": ['BW', 'LS', 'MZ', 'NA', 'SZ', 'ZW'],
"ZM": ['AO', 'BW', 'CD', 'MW', 'MZ', 'NA', 'TZ', 'ZW'], "ZM": ['AO', 'BW', 'CD', 'MW', 'MZ', 'NA', 'TZ', 'ZW'],
"ZW": ['BW', 'MZ', 'ZA', 'ZM'], "ZW": ['BW', 'MZ', 'ZA', 'ZM']
} }
@@ -208,16 +208,21 @@ def main():
args = parser.parse_args() args = parser.parse_args()
search_country = args.country # Strip whitespaces and uppercase input
search_country = args.country.strip().upper()
recursion_depth = args.recursion recursion_depth = args.recursion
if recursion_depth > 12: if recursion_depth > 12:
sys.exit("Recursion should be less than or equal 12! You doing something stupid here.") sys.exit("Recursion should be less than or equal 12! You doing something stupid here.")
result = set(NEAR_COUNTRIES[search_country]) result = {search_country}
for i in range(1, recursion_depth, 1): for i in range(recursion_depth):
n_c = list(result) n_c = list(result)
for country in n_c: for country in n_c:
result.update(NEAR_COUNTRIES[country]) result.update(NEAR_COUNTRIES.get(country,[]))
# Remove search country from result
result.discard(search_country)
list_result = list(result) list_result = list(result)
list_result.sort() list_result.sort()