Skip to content
Snippets Groups Projects
tdd_exo_2.py 760 B
Newer Older


class CityFinder:

    __cities = ['Paris', 'Budapest', 'Skopje', 'Rotterdam', 'Valence', 'Vancouver', 'Amsterdam', 'Vienne', 'Sydney',
                'New York', 'Londres', 'Bangkok', 'Hong Kong', 'Dubaï', 'Rome', 'Istanbul']

    def get_all_cities(self):
        return self.__cities

    def search_city(self, search: str):
        if isinstance(search, str) is False:
            raise TypeError('The parameter "search" must be a string')

        if search == '*':
            return self.__cities

        if len(search) < 2:
            return

        results = list()

        for city in self.__cities:
            if search.lower() in city.lower():
                results.append(city)

        if len(results) >= 1:
            return results