data = [ [(1, 1, 0, ['EARTH']), (1, 2, 0, ['SUGLINOK'])], [(2, 1, 0, ['EARTH']), (2, 2, 0, ['PESOCHEK'])], [(3, 1, 0, ['EARTH']), (3, 2, 0, ['SUGLINOK'])]]
I need to output a list of points based on this logic:
in the list data[0] there is a point (1, 1, 0, ['EARTH']) - write it to the result.
there is a point in the list data[0] (1, 2, 0, ['SUGLINOK']) - write it to the result.
in the list data[1] there is also a point (2, 1, 0, ['EARTH']) - with the same description as in the previous list, which means we do not write it to the result.
in the list data[1] there is a point (2, 2, 0, ['PESOCHEK']) - write it to the result.
in the data[2] list there is a point (3, 1, 0, ['EARTH']) - with the same description as in the previous list, which means we do not write it to the result.
in the list data[2] there is a point (3, 2, 0, ['SUGLINOK']) - we write it to the result, because there is no such thing in the previous list
The result should look like this:
result = [(1, 1, 0, ['EARTH']), (1, 2, 0, ['SUGLINOK']), (2, 2, 0, ['PESOCHEK']), (3, 2, 0, ['SUGLINOK'])]
I tried this code but it doesn't work:
data = [ [(1, 1, 0, ['EARTH']), (1, 2, 0, ['SUGLINOK'])], [(2, 1, 0, ['EARTH']), (2, 2, 0, ['PESOCHEK'])], [(3, 1, 0, ['EARTH']), (3, 2, 0, ['SUGLINOK'])]]result = []for sublist in data: for point in sublist: found = False for existing_point in result: if point[:3] == existing_point[:3] and point[3][0] == existing_point[3][0]: found = True break if not found: result.append(point)print(result)