The 'Filter by value' processor in 4CAT has an 'is in the top n results for this attribute' mode which, for example, returns the top 100 items from a dataset sorted by a given column, e.g. likes.
It does this by getting the top 100 values for that column and returning all items with that value, but if (for example) multiple items have the same amount of plays, it will select all of those. So potentially more than 100 matching items are returned.
The naive solution would be return sorted(items, reverse=True)[:100] but sorted() happens in-memory, and that should be avoided for this to also work with (very) large datasets.
The 'Filter by value' processor in 4CAT has an 'is in the top n results for this attribute' mode which, for example, returns the top 100 items from a dataset sorted by a given column, e.g. likes.
It does this by getting the top 100 values for that column and returning all items with that value, but if (for example) multiple items have the same amount of plays, it will select all of those. So potentially more than 100 matching items are returned.
The naive solution would be
return sorted(items, reverse=True)[:100]butsorted()happens in-memory, and that should be avoided for this to also work with (very) large datasets.