User talk:Tonyjv: Difference between revisions

m
Line 34:
:I get it now. Rather than getting the max then plucking those with that length from a list, you calculate the length sort on it and store it, then select from the maximum end of the sorted list until the length is no longer equal to the length of the first. Neat. Thanks for taking the time to explain. --[[User:Paddy3118|Paddy3118]] 21:07, 20 September 2011 (UTC)
 
:Sorting is slow because it takes O(n log n) time. You are correct that your previous solution also used sorting, by <code>groupby(sorted(...))</code>, and thus also incurred the cost of sorting, and thus was no better. However, the solutions that use sorting (Tonyjv's solution and the other one using groupby) are still inferior to the solutions that use a hash table based dictionary or equivalent (defaultdict, Counter) to group which are much faster -- linear time on average -- assuming the hash function is not terrible. --[[User:Spoon!|Spoon!]] 01:43, 21 September 2011 (UTC)
Anonymous user