<br><br><div class="gmail_quote">2008/11/19 Johannes Bauer <span dir="ltr"><<a href="mailto:dfnsonfsduifb@gmx.de">dfnsonfsduifb@gmx.de</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi group,<br>
<br>
if I remember correctly, wasn't there a way to quickly iterate through<br>
nested loops? Something like<br>
<br>
a = { "a", "b", "c" }<br>
b = { 4, 9, 13}<br>
for (x, y) in someoperator(a, b):<br>
        print(x, y)<br>
<br>
which would print all tuples of<br>
"a", 4<br>
"a", 9<br>
"a", 13<br>
"b", 4<br>
"b", 9<br>
"b", 13<br>
"c", 4<br>
"c", 9<br>
"c", 13<br>
<br>
(not nececssarily in that order, of course).<br>
<br>
Thanks,<br>
Johannes<br>
<br>
--<font color="#888888"><br>
</font></blockquote><div></div><div>If you are running the code in python 3, as suggested by the use of the set literals, the mentioned itertools.product() is probably the straightforward way. </div><div>Another possibility could be a nested generator expression (here using lists - preserving the order):</div>
<div></div><div>>>> a = ["a", "b", "c"]<br>>>> b = [4, 9, 13]<br>>>> for item in ((ax, bx) for ax in a for bx in b): print item<br>...     <br>('a', 4)<br>('a', 9)<br>
('a', 13)<br>('b', 4)<br>('b', 9)<br>('b', 13)<br>('c', 4)<br>('c', 9)<br>('c', 13)<br>>>> <br></div><div><div></div><div>regards </div><div>   vbr</div> </div>
</div>