Mac,<div><br></div><div>this is what I get:</div><div><br></div><div><div>>>> for prod in itertools.product('ABC', 2):</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>print(prod)</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>Traceback (most recent call last):</div><div> File "<pyshell#34>", line 1, in <module></div><div> for prod in itertools.product('ABC', 2):</div>
<div>TypeError: 'int' object is not iterable</div></div><div><br></div><div><br></div><div>hmm, what might be that 'int' object? 2?</div><div><br></div><div><br><div class="gmail_quote">2010/7/28 ZUXOXUS <span dir="ltr"><<a href="mailto:zuxoxus@gmail.com">zuxoxus@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div>Sharp thanks, but:</div><div><br></div><div>I try to reproduce the example from the table, but:</div><div><br></div>
<div>>>> import itertools</div><div>>>> combinations('ABC', 2)</div><div>Traceback (most recent call last):</div>
<div> File "<pyshell#27>", line 1, in <module></div><div> combinations('ABC', 2)</div><div>NameError: name 'combinations' is not defined</div><div>>>> </div><div><br></div>
<div>If im not mistaken, it should return AB, AC, BA, etc.</div><div><br></div><div>I'm using Python 3.1</div><div><br></div><br><div class="gmail_quote">2010/7/28 Mark Lawrence <span dir="ltr"><<a href="mailto:breamoreboy@yahoo.co.uk" target="_blank">breamoreboy@yahoo.co.uk</a>></span><div>
<div></div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div>On 27/07/2010 23:20, ZUXOXUS wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div>
Hi all pythoners<br>
<br>
I've got a probably easy to answer question.<br>
<br>
Say I've got a collections of strings, e.g.: 'man', 'bat', 'super', 'ultra'.<br>
<br>
They are in a list, or in a sequence or whatever, say a bag of words<br>
<br>
And now I want to know how many couples I can do with them, and I want the<br>
program to show me the actual couples: 'manman', 'manbat', 'mansuper',<br>
'manultra', 'batbat', 'batman', 'batsuper', etc.<br>
<br>
But hey, why building up new words from just two strings? I also want to<br>
know the possible combinations of three words, four words, and perhaps, why<br>
not, five words.<br>
<br>
So, is it easy to do?<br>
<br>
Sorry, I'm new in programing, and am probably far from being a math-master<br>
<br>
I'm clueless, I think probably the code have some FOR I IN SEQUENCE... but<br>
then what? I don't know how to say: take every element and paste it to<br>
another one from the bag, and with another one, and with another one,...<br>
<br>
If it's too complex, I dont need the whole code recipe, just need some<br>
clues, or perhaps a useful link<br>
<br>
Thank you very much in advance!<br>
<br></div></div><div>
_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</div></blockquote>
<br>
The lazy way.<div><br>
<a href="http://docs.python.org/library/itertools.html" target="_blank">http://docs.python.org/library/itertools.html</a><br></div>
Look for combinations().<br>
<br>
HTH.<br><font color="#888888">
<br>
Mark Lawrence.</font><div><div></div><div><br>
<br>
<br>
_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</div></div></blockquote></div></div></div><br>
</blockquote></div><br></div>