
Oct. 7, 2011
6:07 a.m.
On Fri, 7 Oct 2011 11:46:34 +0100 Jakob Bowyer <jkbbwr@gmail.com> wrote:
As far as I know and from asking my lecturer, multiplication only produces Cartesian products.
Given that multiplying a list or tuple repeats the sequence, there may be a certain amount of confusion. Also, I don't think itertools.product is common enough to warrant an operator. There's a very readable alternative:
a = {"amy", "martin"} b = {"smith", "jones", "john"} {(u, v) for u in a for v in b} {('amy', 'john'), ('amy', 'jones'), ('martin', 'jones'), ('martin', 'smith'), ('martin', 'john'), ('amy', 'smith')}
Or, in the case where you only want to iterate, two nested loops will suffice and avoid building the container. Regards Antoine.