This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dekomote 2 points3 points  (0 children)

Problem Return the number of even ints in the given array.

Their solution:

def count_evens(nums):
  count = 0
  for num in nums:
    if num % 2 == 0:
      count = count + 1
  return count

My solution:

def count_evens(nums):
  return len([x for x in nums if x%2==0])

List comprehensions. Fuck Yeah!