list to list of pairs
Steve Holden
sholden at holdenweb.com
Mon Nov 19 13:39:21 EST 2001
More information about the Python-list mailing list
Mon Nov 19 13:39:21 EST 2001
- Previous message (by thread): list to list of pairs
- Next message (by thread): Steering novices in the right direction
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
<bvdpoel at uniserve.com> wrote ... > > I've sure I've seen this somewhere...but I can't today... > > I need to convert a list like [1,2,3,4,5,6] to a list of pairs [[1,2], > [3,4], [5,6]]. Isn't there a way to do this with map() or zip()??? > >>> def pairs(l): ... return [[l[i], l[i+1]] for i in range(0, len(l), 2)] ... >>> pairs([1,2,3,4,5,6]) [[1, 2], [3, 4], [5, 6]] >>> regards Steve --- http://www.holdenweb.com/
- Previous message (by thread): list to list of pairs
- Next message (by thread): Steering novices in the right direction
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list