Advertisement
Guest User

help on Implementing a list of dicts with no data pattern

a guest
May 8th, 2013
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. highway_dict = {}
  2. aging_dict = {}
  3.  
  4. queue_row = []
  5. for content in file_content:
  6.  
  7.     if 'aging' in content:
  8.         # aging 0 100
  9.         collumns = ', '.join(map(str, content[:1])).replace('-','_').lower()
  10.         total_values =''.join(map(str, content[1:2]))
  11.         aging_values = '\t'.join(map(str, content[2:]))
  12.  
  13.         aging_dict['total'], aging_dict[collumns] = total, aging_values
  14.     queue_row.append(aging_dict)
  15.  
  16.  
  17.     if 'highway' in content:
  18.         #highway    |   4   |   disable |   25
  19.         collumns = ''.join(map(str, content[:1])).replace('-','_').lower()
  20.         lanes_values  =''.join(map(str, content[1:2]))     
  21.         state_values = ''.join(map(str, content[2:3])).strip('')
  22.         limit_values = ''.join(map(str, content[3:4])).strip('')
  23.        
  24.         highway_dict['lanes'], highway_dict['state'], highway_dict['limit(mph)'] = lanes, state, limit_values
  25.     queue_row.append(highway_dict)
  26.  
  27.    
  28. # FILE OUTPUT DESIRED:
  29. # aging:
  30. # aging  |total     |age
  31. # aging  |0         |100
  32. # aging  |2         |115
  33. # aging  |3     |1
  34. # aging  |4         |10
  35.  
  36. # highway:
  37. # highway   | lanes     |   state   |   limit(mph)
  38. # highway   |   4   |   disable |   25
  39. # highway   |   2   |   disable |   245
  40. # highway   |   3   |   disable |   125
  41. # highway   |   2   |   enable  |   255
  42. # highway   |   3   |   disable |   212
  43. # highway   |   8   |   disable |   78
  44.  
  45. # FILE INPUT EXCERPT EXAMPLE:
  46.  
  47. # aging 0 100
  48. # aging 2 115
  49. # aging 3 1
  50. # highway 4 disable 25
  51. # highway 2 disable 245
  52. # highway 0 disable 125
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement