Getting started
The library is very straight forward, at the very top of the library there is country which is tanzania and at the very bottoms are places in a given street and you access the locations as attributes just as shown in the example below;
#
Example#
How about Dar-es-salaam ?In the above example we were able to retreive locations of Mbeya region because, Mbeya is a valid python identifier, when you try to access Dar-es-Salaam it will ofcourse raise you an error just as shown below;
To resolve this at anypoint where you a location name is an invalid identifier, use get_dict() instead of (.) operator to access it as shown in the example below;
#
Types ?Since we can access the attributes by locations it obviously the tanzania is an Abstract data type (ADT) implemented using a class, we can see this by using python builtin functionality type();
In many cases you will want those locations to be in standard types whether that a list, tuple, or set to easy manipulate and interact with them as build an application but how ?
tip
tanzania object is iterable, that's means you can easy convert locations at any level location into any iterable standard type whether that be a list, set or a tuple just as shown in the example below;
#
Looping over locationsAs we have seen that since mtaa.Tanzania is an iterable, then thats means we can also loop through it.
note
When we loop over a Mtaa.Tanzania , we are looping the locations as strings not objects, here an example on what I mean;
If were to find the all the district in Mbeya that starts with R, our code is going to look like this;
In the next chapter we will see how to use mtaa to retrieve grouped locations data so keep reading