Skip to content
Advertisement

select top 3 unique items in a list of list

I have a list of items and it outputs a list of list:

JavaScript

Is there a way to get the output as a unique list of items that contains the top 3 items from each sublist but also not in the initial item_list?

so that the output will look like (in the exact order):

JavaScript

or if possible:

JavaScript

Advertisement

Answer

You must keep a set of already seen items to find the unique ones. A trivial implementation would be:

JavaScript

output:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement