I suppose practice. Practice list comprehensions enough and it can get easy. This is a list comprehension that adds 1 to a list everytime the sum in that range is equal to d. Then len is used to count all the 1s in that list. I learned list comprehensions through learning haskell.