Hello all,

I have the following function that uses an intermediate iterator
"rawPairs":

def MakePairs(path):
    import os
    import operator
    join = os.path.join
    rawPairs = (
        (join(path, s), func(s))
        for s in os.listdir(path)
        if func(s) is not None and func(s).endswith("some criterion")
    )
    #Use the second item in the pair as the sort criterion
    result = sorted(rawPairs, key=operator.itemgetter(1))
    return result

where "func" is a single-argument function that returns either a
string or None, but is an expensive call.
I am pretty sure that the sorted() construct cannot be improved much
further, but...
...does anyone have ideas on improving the "rawPairs" iterator so that
it calls "func(s)" only once per iteration?  Perhaps a lambda
construct, but I am not sure how to go about it...?

Cheers,
Basilisk96
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to