Sorry if that sounds extremely confusing, but basically I've got a two column array storing a list of 2D coordinates:
array([[ 0.31730234, 0.73662906],
[ 0.54488759, 0.09462212],
[ 0.07500703, 0.36148366],
[ 0.33200281, 0.04550565],
[ 0.3420866 , 0.9425797 ],
[ 0.36115391, 0.16670599],
[ 0.95586938, 0.52599398],
[ 0.13707665, 0.6574444 ],
[ 0.77766138, 0.56875582],
[ 0.79618595, 0.7139309 ]])
I've got a list of dictionaries and in each of these dictionaries there is a list of random combinations of these coordinates under a key called 'coordinates'.
How do I make a function that, if a random set of coordinates is given, checks if these coordinates are present in any of the dictionaries, and then returns the index of the dictionary its present in?
Obviously the arguments are the list of dictionaries (since I actually have multiple lists of them) and the coordinate id in the array. Every time I try something with the any function or enumerate or find, I get syntax errors - e.g.:
def whichcluster(list,coordinate_id):
.....: for elem in list:
.....: if any(x in elem['coordinates'] for coordinate_id):
.....: return list.index(elem)
.....: else:
.....: return False
Why isn't this working?
list
as a variable name. – eumiro Dec 28 '12 at 12:10