Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
You do a lookup in the whole set for each element, and still your code is very fast! I did kinda the same thing first but with a list and it becomes super slow when doing real work > 50k records.
I benchmarked 5 million records, and your code does it in: 10.307 seconds! (Didn't know set's where that fast.)
Mine don't check the whole list each time but could only manage: 3.9 seconds. (Yes it's faster but I needed way more code and tinkering. Your code has great roi.)
For 50 million records: your code does it in: 104.951 seconds.
For 50 million records: mine does it in: 52.141 seconds.
Without the conversion the lookup would be
O(n)
instead ofO(1)
.This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Oh yes thanks for pointing it out!
Ternary is something like
return A if B else C
This is list comprehension.