From 2176c244ea8c1d9211139357e363e2e691979629 Mon Sep 17 00:00:00 2001 From: Kira <38155247+Nyanraltotlapun@users.noreply.github.com> Date: Tue, 30 Dec 2025 15:34:20 +0100 Subject: [PATCH] Remove input country from output. Accept lower case country codes. --- src/get_near_countries.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/get_near_countries.py b/src/get_near_countries.py index 59eb54d..1dbef6c 100755 --- a/src/get_near_countries.py +++ b/src/get_near_countries.py @@ -182,7 +182,7 @@ NEAR_COUNTRIES = { "YE": ['OM', 'SA'], "ZA": ['BW', 'LS', 'MZ', 'NA', 'SZ', 'ZW'], "ZM": ['AO', 'BW', 'CD', 'MW', 'MZ', 'NA', 'TZ', 'ZW'], - "ZW": ['BW', 'MZ', 'ZA', 'ZM'], + "ZW": ['BW', 'MZ', 'ZA', 'ZM'] } @@ -208,18 +208,22 @@ def main(): args = parser.parse_args() - search_country = args.country + # Strip whitespaces and uppercase input + search_country = args.country.strip().upper() + recursion_depth = args.recursion if recursion_depth > 12: sys.exit("Recursion should be less than or equal 12! You doing something stupid here.") - result = set(NEAR_COUNTRIES.get(search_country,[])) - for i in range(1, recursion_depth, 1): + for i in range(1, recursion_depth): n_c = list(result) for country in n_c: result.update(NEAR_COUNTRIES.get(country,[])) + # Remove search country from result + result.discard(search_country) + list_result = list(result) list_result.sort() sys.stdout.write(' '.join(list_result))