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.
For more information on this look at YouTube, Cory Shaffer - "Python Tutorial: Comprehensions - How they work and why you should be using them"
filter and list comprehension are exactly the same (in terms of algorithms)
How about using filter() function. Is this option more optimal?
why just not set(b)?
It depends. If you want a O(1) space complexity, sorting is required. If you have extra space available, you can use my solution, which has a time complexity of O(a+b) as opposed to sorting's O(n log n) complexity.
You have made a flawed assumption! :)
Best practice and optimum solutions are not necessarily the same thing.
This is best practice, because it is concise, clear, and written as idiomatic Python, so most Python devotees will 'just get it'.
But there are many ways to skin a proverbial cat...
Your suggested approach has merits, but personally for very large arrays I would first sort the arrays then step my access index forward though each value depending on <, ==, or > greater than comparison results of the elements.
As a seasoned professional software developer though, I'll give you these words of advice:
Chris (Your friendly local performance-tuning guru. (No honestly I write trading systems for investment banks where every microsecond counts!))
Yes, list comprehensions are considered to be more readable and thus preferable to using
filter()
andmap()
.For example, see http://stackoverflow.com/questions/5426754/google-python-style-guide
Also, iterations like
c for c in string
are preferable to using indexes likestring[i] for i in xrange(len(string))
.