List mapping?

Alex cut_me_out at hotmail.com
Thu Apr 13 16:53:13 CEST 2000


from operator import getitem

def pair (l):
    assert len (l) % 2 == 0
    evens = range (0, len (l), 2)
    evens = map (getitem, len (evens) * [l], evens)
    odds = range (1, len (l), 2)
    odds = map (getitem, len (odds) * [l], odds)
    return map (None, evens, odds)

if __name__ == '__main__':
    print pair (range (10))

Alex.



More information about the Python-list mailing list