[FRPythoneers] Opps.

Eric Brunson brunson at level3.net
Tue Aug 6 16:01:50 MDT 2002


I thought there was a flatten function added in 2.2, but I can't find
it.

Here's a function for you, though:

def summate( *args ):
    sum = None
    for arg in args:
        if sum:         
            sum = sum + arg
        else:
            sum = arg
    return sum


apply( summate, [[1,2,3],[4,5,6],[7,8,9]] )
yields:
[1, 2, 3, 4, 5, 6, 7, 8, 9]

Because of the funky way I did the initialization of sum (to avoid
assuming the type of the operands) you also end up with:

apply( summate, [ 'now', 'is', 'the', 'time' ] )
yields:
nowisthetime

and

print apply( summate, [1, 2, 3, 4, 5, 6, 7, 8, 9] )
yields:
45

* marciot (marciot at holly.colostate.edu) [020806 15:40]:
> >===== Original Message From frpythoneers at lists.community.tummy.com =====
> >Hi,
> >
> >I was looking for an easy way to convert a list of lists into a flattened
> >list:
> >
> >>> a = somefunc([[1,2,3],[4,5,6],[7,8,9]])
> >>> print a
> >[1,2,3,4,5,6]
> 
> I meant, [1,2,3,4,5,6,7,8,9], of course :)
> 
> 
> _______________________________________________
> This message sent by the FRPythoneers mailing list.
> Unsubscribe: echo unsubscribe | FRPythoneers-request at lists.community.tummy.com
> URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers


-- 
      Eric Brunson        brunson at level3 dot net
tcA thgirypoC muinelliM latigiD eht detaloiv tsuj evah uoY



More information about the FRPythoneers mailing list