[Tutor] Re: Soem list operation questions?

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Tue Dec 28 11:09:33 CET 2004


kilovh wrote:
> 2. Is there any way to take seperate integers in a list and combine them 
> into digits of one number? (e.g. changing [1,2,3,4] into 1234)

Instead of using strings as in the other replies, it's also possible to 
take the math approach:

def listtoint(digits):
     result = 0
     for digit in digits:
         result *= 10
         result += digit
     return result

-- 
"Codito ergo sum"
Roel Schroeven



More information about the Tutor mailing list