Advertisement
vikramk3

users.py

Oct 15th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Sep 24 22:12:20 2014
  4.  
  5. @author: vikramk3
  6. """
  7.  
  8. #!/usr/bin/env python
  9. # -*- coding: utf-8 -*-
  10. import xml.etree.ElementTree as ET
  11. import pprint
  12. import re
  13. """
  14. Your task is to explore the data a bit more.
  15. The first task is a fun one - find out how many unique users
  16. have contributed to the map in this particular area!
  17.  
  18. The function process_map should return a set of unique user IDs ("uid")
  19. """
  20.  
  21. def get_user(element):
  22.     return
  23.  
  24.  
  25. def process_map(filename):
  26.     # I added element.clear() after each iteration to avoid memory issues for the iterative parsing
  27.     users = set()
  28.     for _, element in ET.iterparse(filename):
  29.         pass
  30.         new_user=element.get("uid")
  31.         if (new_user not in users) and (new_user != None):
  32.             users.add(element.get("uid"))
  33.         element.clear()
  34.  
  35.     return users
  36.  
  37.  
  38. def test():
  39.  
  40.     users = process_map('C:\\Users\\vikramk3\\Documents\\Courses\\Data_Wrangling\\austin_texas.osm')
  41.     pprint.pprint(users)
  42.     print "#of unique users= ", len(users)
  43.  
  44.  
  45.  
  46. if __name__ == "__main__":
  47.     test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement