I'm trying to create hierarchy lists python in python. For example, There are several states. In each state there are several counties, in each county they are several cities. Then I would like be able to call those. I've tried creating list and appending lists to those list but I can't get to that to work. It also gets really messy. Thanks
I just found this example:
tree = [
['Food', [
['Fruit', [
['Red', ['Cherry', 'Strawberry']],
['Yellow', ['Banana']],
]],
['Meat', [
['Beef', 'Pork']
]],
]],
]
Now my question would just be, is this the best way? how to call specific things? If I use...
print tree[0]
it will give me everything. When I try
print tree[0[1]]
I get a type TypeError: 'int" object has no attribute '__getitem_' Thanks
{'country_1': {'state_1': {'county_1': ['city_1', 'city_2',], 'county_2': ['city_3', 'city_4']}, 'state_2': {'county_3': ...etc.print tree[0[1]], tryprint tree[0][1].