I have a list:
df = [['apple', 'red', '0.2'], ['apple', 'green', '8.9'], ['apple', 'brown', '2.9'],
['guava', 'green', '1.9'], ['guava', 'yellow', '4.9'], ['guava', 'light green', '2.3']]
From here I want to only get the first 2 items from the first distinct sublist given the condition that the value of the first sublist is unique.
Expected output:
df = [['apple', 'red'], ['guava', 'green']]
Code till now:
dummy_list = []
for item in df:
if item[0] not in dummy_list:
dummy_list.append(item[:2])
This is not working and appending all the elements. Any help on this please