News for hackers. Stuff that matters.
Re:Anti-Patterns in Python Programming by a3n on Wednesday July 09, 2014 @10:37AM (#8009814)
Don't know if this is why, but the list comprehension takes an expression at the "foo(word)" location, and is therefore more general than map, which requires a function. The comprehension in that case is simpler.

  words = ['w1', 'w2', 'w3']

  [word[1] for word in words]

  ['1', '2', '3']
  
  map(lambda x: x[1], words)

  ['1', '2', '3']
I like looking at the list comprehension better. The use of lambda looks forced in this case. I also imagine there's a penalty for calling the (anonymous) function in map.
Re:Anti-Patterns in Python Programming by icebraining on Wednesday July 09, 2014 @07:11PM (#8012727)
In that case I'd use

  map(itemgetter(1), words)
Re:Anti-Patterns in Python Programming by a3n on Wednesday July 09, 2014 @09:48PM (#8013169)
Instead of my map example, or instead of a list comprehension in general?
Re:Anti-Patterns in Python Programming by icebraining on Thursday July 10, 2014 @04:21AM (#8014148)
Instead of a list comprehension equivalent to your example.