<br><br><div class="gmail_quote">On Mon, Feb 8, 2010 at 4:15 PM,  <span dir="ltr">&lt;<a href="mailto:internets@shaneferguson.com">internets@shaneferguson.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

I&#39;ve been trying to work my way through some &#39;beginner projects&#39; I found<br>
around the web, one of them involves generating some random numbers.  I<br>
decided to use a list of lists, and I&#39;m wondering if this is a valid<br>
comprehension...IDLE doesn&#39;t seem to mind, but maybe I lack the experience<br>
to know better:<br>
<br>
numbers = [[random.randint(1, 10) for x in range(5)] for y in range(5)]<br>
<br>
I&#39;m using Python 3.1.  If this is valid, is there a shorter version or<br>
better way?<br></blockquote><div> <br>If Python executes it without throwing exceptions that means it&#39;s syntactically valid.  Are you 
asking if it&#39;s semantically valid?  Well, that depends what you&#39;re 
trying to do.  Are you trying to make a 5x5 matrix of random numbers chosen from [1,2,3,4,5,6,7,8,9,10]?  In that case I&#39;d
 say it does what you want.  most people opt to use randrange rather than randint though as it makes more sense when related to other range functions.<br></div></div><br>