@@ -0,0 +1,2499 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0Aimport xml.etree.cElementTree as ET%0Aimport pprint%0Aimport re%0Aimport os%0A%22%22%22%0AYour task is to explore the data a bit more.%0ABefore you process the data and add it into your database, you should check the%0A%22k%22 value for each %22%3Ctag%3E%22 and see if there are any potential problems.%0A%0AWe have provided you with 3 regular expressions to check for certain patterns%0Ain the tags. As we saw in the quiz earlier, we would like to change the data%0Amodel and expand the %22addr:street%22 type of keys to a dictionary like this:%0A%7B%22address%22: %7B%22street%22: %22Some value%22%7D%7D%0ASo, we have to see if we have such tags, and if we have any tags with%0Aproblematic characters.%0A%0APlease complete the function 'key_type', such that we have a count of each of%0Afour tag categories in a dictionary:%0A  %22lower%22, for tags that contain only lowercase letters and are valid,%0A  %22lower_colon%22, for otherwise valid tags with a colon in their names,%0A  %22problemchars%22, for tags with problematic characters, and%0A  %22other%22, for other tags that do not fall into the other three categories.%0ASee the 'process_map' and 'test' functions for examples of the expected format.%0A%22%22%22%0A%0A%0Alower = re.compile(r'%5E(%5Ba-z%5D%7C_)*$')%0Alower_colon = re.compile(r'%5E(%5Ba-z%5D%7C_)*:(%5Ba-z%5D%7C_)*$')%0Aproblemchars = re.compile(r'%5B=%5C+/&%3C%3E;%5C'%22%5C?%25#$@%5C,%5C. %5Ct%5Cr%5Cn%5D')%0A%0A%0Adef key_type(element, keys):%0A    if element.tag == %22tag%22:%0A        # YOUR CODE HERE re.match(lower, element.attrib%5B'k'%5D, flags=0)%0A        if re.search(lower, element.attrib%5B'k'%5D):%0A            keys%5B%22lower%22%5D += 1%0A        elif re.search(lower_colon, element.attrib%5B'k'%5D):%0A            keys%5B%22lower_colon%22%5D += 1%0A        elif re.search(problemchars, element.attrib%5B'k'%5D):%0A            keys%5B%22problemchars%22%5D += 1%0A        else:%0A            keys%5B%22other%22%5D += 1%0A        pass%0A    return keys%0A%0A%0A%0Adef process_map(filename):%0A    keys = %7B%22lower%22: 0, %22lower_colon%22: 0, %22problemchars%22: 0, %22other%22: 0%7D%0A    for _, element in ET.iterparse(filename):%0A        keys = key_type(element, keys)%0A%0A    return keys%0A%0A%0A%0Adef test():%0A    # You can use another testfile 'map.osm' to look at your solution%0A    # Note that the assertion below will be incorrect then.%0A    # Note as well that the test function here is only used in the Test Run;%0A    # when you submit, your code will be checked against a different dataset.%0A    os.chdir('./data')%0A    keys = process_map('example1.osm')%0A    pprint.pprint(keys)%0A    assert keys == %7B'lower': 5, 'lower_colon': 0, 'other': 1, 'problemchars': 1%7D%0A%0A%0Aif __name__ == %22__main__%22:%0A    test()

Add a script which check the <k> value for each <tag> and see if there are any potential problems