The .index method does a linear search, checking on average 1/2 of the
items in the list. That's why it's so slow.

In order to avoid that you could build a dict of each value in
dimension_values[col_idx] and its index in a single pass so that it
becomes a quick lookup.

For example:

from itertools import count, izip

...
def main():
    # dimension_names = ["color", "size"]
    dimension_cols = [0, 1]

    # measure_names = ["weight", "value"]
    measure_cols = [2, 3]

    indexers = [Indexer() for _ in dimension_cols]

    facts = pairs(iterator_factory(),
                  dimension_cols, measure_cols, indexers)
    facts = list(facts)

    print facts
    for i, indexer in enumerate(indexers):
        print "%d: %s" % (i, indexer.to_list())

if __name__ == "__main__":
    main()
Whew! :-) Thank you for taking the time. I'm not very familiar to itertools yet, so I need some time to understand this *beautiful* code. :-)

L

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to