"Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | "Terry Reedy" <[EMAIL PROTECTED]> writes: | | > "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message | > news:[EMAIL PROTECTED] | > | > here is a very sophisticated implementation :) | > | >>>> def extract(indices, seq): | > ... return tuple(seq[i] for i in indices) | > ... | >>>> y, d = extract((0, 2), time.localtime()) | >>>> y, d | > (2008, 12) | > | > =================== | > Or a generator version: | > | > # 3.0 | > def extract(iterable, indexes): | > # assume indexes are all legal
and in order, I wrote once, but seem to have erased in revising (frown) | > enext = enumerate(iterable).__next__ | > i,item = enext() | > for index in indexes: | > while i < index: | > i,item = enext() | > yield item | > | > import time | > print(list(extract(time.localtime(), (0,2)))) | > | > #prints [2008, 12] | | but extract('python', (3, 1)) won't work! -- http://mail.python.org/mailman/listinfo/python-list