Solving the code challenge with list comprehension

I think i’ve got an elegant solution but I’m wondering if i should make a new variable for the lenght of the list or is it ok to just return len(list)?

def divisible_by_ten(nums):
  divisible = [num for num in nums if num % 10 == 0]
  return len(divisible)
2 Likes

If list comprehensions have not been taught up to this point, then one should probably venture into other possible solutions that make use of what has been taught so far. Don’t skip the naive training, or you miss out on some important discoveries and hidden details.

As for your question, an intermediary variable is not really necessary since it is only the return. len(list) is ample.

1 Like

Thanks! We had comprehension a few lessons before so that’s why I wanted to use it.

1 Like