Hacker News new | past | comments | ask | show | jobs | submit login

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.

And not to start a flame war, but the code:

  numbers = [1,10,100,1000,10000]
  if [number for number in numbers if number < 10]:
      print 'Success'
  # Output: 'Success!'
actually does say that it's less efficient... granted it's buried in a paragraph so it's maybe not too obvious ; )... if you're using Genshi or something similar though you need to be able to toss crazy things in one line sometimes.

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

  s = foo and "word: "+foo or ""
I tried it and "" got assigned to s...

And dude, the string in substring syntax is awesome!




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.


This is completely unrelated, but why do some comments render at a lighter shade of gray than other comments? This comment renders at #323232, and the rest of them render at #000


Comments with 1 point or fewer are rendered in progressively grayer text, presumably to make them easier to filter out visually.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: