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
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:])
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,
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())
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)):