Wikipedia has a list of Hungarian cities, and this library parses it into city -> county tuples or dictionary.
The following functions of the generator module can be used to parse the input.
generate_itemsis a generator and yields(city, county)tuplesgenerate_dictreturns a city -> county dictionarygenerate_pickledsaves such a dictionary into a Pickle file
The generator module can also be called from the command line with a file
argument, as it can be seen in the following example.
$ python generator.py output.pickle
The lookup modules has a Lookup class, which can be instantiated with a
string parameter having the name of a Pickle file generated by generator.
The get method can be used to get the county associated with a certain
city. The lookup module can also be called from the command line with
two arguments as it can be seen in the following example.
$ python lookup.py test.pickle Budapest
Budapest
The whole project is available under MIT license.
- Python 2.x (tested on 2.7.3)
- lxml (Debian/Ubuntu package:
python-lxml)