Efficient coding advice?

Alex cut_me_out at hotmail.com
Tue Apr 25 09:22:01 EDT 2000

> 1.  Is there an easy way to split a large string so that every-other
> element gets assigned to an array?

Not really easy, but it might be fast:
from operator import getitem

def odds_and_evens (l):
    length = len (l)
    even_indices = range (0, length, 2)
    odd_indices = range (1, length, 2)
    even_elements = map (getitem, len (even_indices) * [l], even_indices)
    odd_elements = map (getitem, len (odd_indices) * [l], odd_indices)
    return even_elements, odd_elements

> 2.  Is there an easy way to turn an entire array of characters into
> their ord value?

map (ord, l)


More information about the Python-list mailing list