Re: An easier way to do this? (spoiler if you're using pyschools for fun)

2010-11-10 Thread Matteo Landi
I agree with Peter: * iterate over the list directly * use %10 instead of string conversion + slice (*) use genexps Good luck, Matteo On Tue, Nov 9, 2010 at 8:18 PM, Terry Reedy tjre...@udel.edu wrote: On 11/9/2010 2:00 PM, Matty Sarro wrote: I'm working on one of the puzzles on pyschools.com

An easier way to do this? (spoiler if you're using pyschools for fun)

2010-11-09 Thread Matty Sarro
Hey everyone, I'm working on one of the puzzles on pyschools.com, and am trying to figure out if I can make my solution a bit more elegant. def getSumOfLastDigit(numList): sumOfDigits=0 for i in range(0, len(numList)): num=str(numList.pop()) sumOfDigits+=int(num[-1:])

Re: An easier way to do this? (spoiler if you're using pyschools for fun)

2010-11-09 Thread Chris Rebert
On Tue, Nov 9, 2010 at 11:00 AM, Matty Sarro msa...@gmail.com wrote: Hey everyone, I'm working on one of the puzzles on pyschools.com, and am trying to figure out if I can make my solution a bit more elegant. def getSumOfLastDigit(numList):     sumOfDigits=0     for i in range(0,

Re: An easier way to do this? (spoiler if you're using pyschools for fun)

2010-11-09 Thread Peter Otten
Matty Sarro wrote: Hey everyone, I'm working on one of the puzzles on pyschools.com, and am trying to figure out if I can make my solution a bit more elegant. def getSumOfLastDigit(numList): sumOfDigits=0 for i in range(0, len(numList)): num=str(numList.pop())

Re: An easier way to do this? (spoiler if you're using pyschools for fun)

2010-11-09 Thread Terry Reedy
On 11/9/2010 2:00 PM, Matty Sarro wrote: I'm working on one of the puzzles on pyschools.com http://pyschools.com, and am trying to figure out if I can make my solution a bit more elegant. Definitely def getSumOfLastDigit(numList): sumOfDigits=0 for i in range(0, len(numList)):