You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
More cases that would now return the expected Country:
United Kingdom
Russia
Syria
Iran
Macedonia (Actually "North Macedonia", so simple prefix /.startswith would not suffice)
This enhancement partially solves #21, though not the specific "South Korea" case.
Independent code to explain behaviour:
fromiso3166importcountries, Countrydefsub_get(partial_name: str) ->CountryorNone:
""" Get the single matching Country from a partial name. partial_name: The country name, or sub-string thereof, to find. Return: None, or the fuzzy matching country name. """name=partial_name.lower()
country=NoneforkeyinINDEX:
ifnameinkey: ### Crux ###ifcountryisnotNone:
# Ambiguous partial_nameraiseKeyErrorcountry=INDEX[key]
returncountryINDEX= {c.name.lower(): cforcincountries}
tests= (
'United Kingdom', 'Iran', 'RUSSIA', 'spam', 'Macedonia', # Passes'New', 'south', ' ', # Raises KeyErrors
)
fortestintests:
print(sub_get(test))
Since all of the country name have to be searched through, this is certainly slower than a dictionary lookup.
The text was updated successfully, but these errors were encountered:
Get the unambiguous matching Country from a partial name.
E.g.
More cases that would now return the expected Country:
.startswith
would not suffice)This enhancement partially solves #21, though not the specific "South Korea" case.
Independent code to explain behaviour:
Since all of the country name have to be searched through, this is certainly slower than a dictionary lookup.
The text was updated successfully, but these errors were encountered: