I am having difficulties with the nested lists of lists in python (this is the structure of geojson coordinates )
Here an example
updated example to avoid confusion
DictofCoordinates = {
'a': [1,1],
'b': [[2, 2], [2,2], [2, 2]],
'c': [[[3,3], [3, 3], [3, 3]]],
'd': [[[41, 41], [41, 41]],
[[42, 42], [42, 42]]]
}
what I want to get is the lists which do not contains anyhing else than the pairs (of coordinates). this is what I call "atomic list of list" (for lack of a better term)
so
- for a : the list [1, 1]
- for b : [[2, 2], [2,2], [2, 2]]
- for c : [[3,3], [3, 3], [3, 3]]
- for d : the two lists [[41, 41], [41, 41]] and [[42, 42], [42, 42]]]
taking inspriation from here that is what I tried
def ExplodeTolist(xList):
for x1 in xList:
if isinstance(x1[0], (float, int, long)):
yield x1
else:
for x2 in ExplodeTolist(x1):
yield x2
but it does not work
for x in ExplodeTolist(DictofCoordinates.values()):
print x
any help appreciated. Thanks