2 ms·
You're right about the map function, it is slightly more efficient in this case. But if you're multiplying 2 numbers together 10 times instead of 5, is it reall
by BrandonM 18y ago
You're right about the map function, it is slightly more efficient in this case. But if you're multiplying 2 numbers together 10 times instead of 5, is it really significantly more efficient to use map? I suppose map/filter vs. list comprehensions/generator functions is really a matter of personal taste.
I don't understand what you mean here. No matter how many numbers you're multiplying, the result is that you're doing twice as many as necessary. Now, with list comprehensions (and a generator for efficiency), it could have been written
squares_under_10 = [sq for sq in (n*n for n in numbers)
if sq < 10]
That is the best of both worlds if you are against the use of map and filter.
And 'Test is False' doesn't have to evaluate to True... if it is false, it is still the value returned by the entire expression. Not the actual value 'False'. I actually disagree with your example
Hmm... very strange, you are absolutely right. I'm almost positive I've been bitten by a bug related to and... or before. It must have been something else, although I'm sure it wasn't the case where the "Test is True" value evaluated to False. Very weird...
And dude, the string in substring syntax is awesome!
I admit that is awesome, I just couldn't remember the last time I'd used index or find, anyways. I'll certainly be using it the next time the opportunity presents itself, though.