Untitled

 avatar
unknown
python
a year ago
874 B
5
Indexable
def filter_and_append_duplicates(data):
    seen_values = {}  # A dictionary to store seen values and their enumerations
    filtered_data = []

    for x, y, enumeration in data:
        key = (x, y)  # Create a unique key based on x and y values
        if key in seen_values:
            seen_values[key].append(enumeration)  # Append enumeration if the value is a duplicate
        else:
            seen_values[key] = [enumeration]  # Initialize with the current enumeration

    # Create the filtered data by combining unique values with appended enumerations
    for key, enumerations in seen_values.items():
        x, y = key
        filtered_data.append((x, y, enumerations))

    return filtered_data

# Example usage:
data = [(1, 2, 'A'), (3, 4, 'B'), (1, 2, 'C'), (5, 6, 'D'), (3, 4, 'E')]
filtered_data = filter_and_append_duplicates(data)
print(filtered_data)
Editor is loading...