[Tutor] List Comprehension question
internets at shaneferguson.com
internets at shaneferguson.com
Mon Feb 8 23:15:33 CET 2010
I've been trying to work my way through some 'beginner projects' I found
around the web, one of them involves generating some random numbers. I
decided to use a list of lists, and I'm wondering if this is a valid
comprehension...IDLE doesn't seem to mind, but maybe I lack the experience
to know better:
numbers = [[random.randint(1, 10) for x in range(5)] for y in range(5)]
I'm using Python 3.1. If this is valid, is there a shorter version or
better way?
Thanks!
More information about the Tutor
mailing list