<div>So you want to convert a list into a tuple. </div>
<div> </div>
<div>Here ya go, using your example of the table setup:</div>
<div> </div>
<div>>>> raw_table ="""<br>%s | %s | %s<br>--------------<br>%s | %s | %s<br>--------------<br>%s | %s | %s<br>"""</div>
<div>>>> from random import choice<br>>>> x_o = [choice(['x','o']) for i in range(9)]<br>>>> x_o<br>['x', 'x', 'x', 'x', 'o', 'o', 'o', 'x', 'x']<br>>>> filled_table = raw_table % tuple(x_o)
<br>>>> print filled_table</div>
<div>
<p>x | x | x<br>--------------<br>x | o | o<br>--------------<br>o | x | x</p>
<p>>>> </p></div>
<div><span class="gmail_quote">On 11/24/06, <b class="gmail_sendername">Mihai Iacob</b> <<a href="mailto:aymchaos@yahoo.com">aymchaos@yahoo.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hello,<br><br>This is my first post so if i make any kind of<br>mistakes take it easy on me :).<br><br>I don't know how to explain clearly what is the
<br>problem but i'll try.<br>table = """<br>%s |%s |%s<br>-----------<br>%s |%s |%s<br>-----------<br>%s |%s |%s<br>"""<br><br>listTable is a dictionary.<br><br>listTable = {0 :'X', 1 :' ' , 2 :' ', 3 :'O', 4 :' ',
<br>5 :' ', 6 :'O', 7 :' ', 8 :'X',}<br><br>I am trying to take the values from the dictionary<br>listTable.values() and print them in the table.<br><br>The problem is that listTable.values() returns a list<br> " ['X', ' ', ' ', 'O', ' ', ' ', 'O', ' ', 'X'] "
<br>and python won't assign the values of the dictionary<br>in the table. " table % listTable.values() "<br><br>This error message appears:<br><br>Traceback (most recent call last):<br>File "<pyshell#81>", line 1, in <module>
<br> table % listTable.values()<br>TypeError: not enough arguments for format string<br><br><br>So instead of the list " ['X', ' ', ' ', 'O', ' ', '<br>', 'O', ' ', 'X'] " which won't let me assign strings<br>
in the table, i want to get ('X', ' ', ' ', 'O', ' ',<br>' ', 'O', ' ', 'X') from listTable.values()<br><br>I know i can make it work using:<br>table % (listTable[0],listTable[1],<br>listTable[2],listTable[3],listTable[4],
<br>listTable[5],listTable[6],listTable[7],listTable[8])<br><br>but it's kinda long.<br><br><br>If somebody can tell me how to convert the []list into<br>() i'll make him a little shrine and worship him for 5<br>seconds :P
<br><br>I'm trying to make a OXO game, so don't give me any<br>hints even if you spot mistakes (i hope i can make it<br>alone)<br><br><br><br><br><br>____________________________________________________________________________________
<br>Do you Yahoo!?<br>Everyone is raving about the all-new Yahoo! Mail beta.<br><a href="http://new.mail.yahoo.com">http://new.mail.yahoo.com</a><br>_______________________________________________<br>Tutor maillist - <a href="mailto:Tutor@python.org">
Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div><br>