hi all,
I've just started back up with python after a looong break - it's great to be back :D
Anyway, I'm going through "how to think like a computer scientist" as a refresher and trying to come up with a function to return the sum of squares for a given number.
I decided to write it as a list comprehension:
I think I read somewhere that type conversion in python was costly? Is there a better way to do this?
Thanks
I've just started back up with python after a looong break - it's great to be back :D
Anyway, I'm going through "how to think like a computer scientist" as a refresher and trying to come up with a function to return the sum of squares for a given number.
I decided to write it as a list comprehension:
Code:
sum(int(i)**2 for i in str(x))
Thanks
Comment