So I have a large amount of data that is stored in a nested list. The nested list has a lot of sublists but it takes the following general form:
nested_list = [[[ID#, Magnitude, Magnitude Error],[ID#, Magnitude, Magnitude Error]],
[[ID#, Magnitude, Magnitude Error],[ID#, Magnitude, Magnitude Error]]]
The ID#, Magnitude and Magnitude Error are all floats. I also have a list of common ID numbers. What I want to do is remove elements that are tagged with an ID# that is not in the common set of ID numbers. Essentially only the ID number matters at this point. I have tried my code with the nested list and data below:
nested_list = [[[1.0, 17.634, 0.025], [4.0, 15.633, 0.015], [8.0, 14.097, 0.023],
[9.0, 15.134, 0.018], [10.0, 15.247, 0.015]],
[[4.0, 19.634, 0.025], [8.0, 10.097, 0.023], [10.0, 15.247, 0.015]],
[[4.0, 13.633, 0.015], [8.0, 12.097, 0.023], [9.0, 15.134, 0.018]]]
common_values = [4.0,8.0]
I was trying to throw out elements that didn't contain one of the common ID numbers. So what would be returned would be:
final_nested_list = [[[[4.0, 15.633, 0.015],[8.0, 14.097, 0.023]],[[4.0, 19.634, 0.025],
[8.0, 10.097, 0.023]], [[4.0, 13.633, 0.015],[8.0, 12.097, 0.023]]]
I ran into trouble trying to figure out how to iterate through only the first element that contained the ID number.