FAQ: Code Challenge: Loops - Divisible by Ten


Without being able to tell, for sure, this sounds like a return inside the loop. Unindent the return line so it matches with count = 0.


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)


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.


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