Challenge Tuples

Andy Valencia dont at spam.me
Fri Apr 26 15:52:04 UTC 2024


On Friday, 26 April 2024 at 13:25:34 UTC, Salih Dincer wrote:
> You have a 5-item data tuples as Tuple(1, 2, 3, [1, 3], 5) and 
> implement the sum (total = 15) with the least codes using the 
> sum() function of the language you are coding...

My Python solution (function named dosum to avoid collision w. 
Python primitive):

def dosum(itm):
     if isinstance(itm, (int, float)):
         return itm
     return sum( dosum(_i) for _i in itm );

print dosum( [1, 2, 3, [1, 3], 5] )



More information about the Digitalmars-d-learn mailing list