On 2/6/2010 2:09 PM, Wolodja Wentland wrote:
On Sat, Feb 06, 2010 at 13:24 -0500, Chris Colbert wrote:
[(match_val_291, identifier_b), (match_val_23, identifier_b), (match_val_22,
identifer_k) .... ]

Now, what I would like to do is step through this list and find the identifier
which appears first a K number of times.

I think you can use the itertools.groupby(L, lambda el: el[1]) to group
elements in your *sorted* list L by the value el[1] (i.e. the
identifier) and then iterate through these groups until you find the
desired number of instances grouped by the same identifier.

This will generally not return the same result. It depends on whether OP wants *any* item appearing at least 5 times or whether the order is significant and the OP literally wants the first. Sorting the entire list may also take a *lot* longer.

Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to