[Tutor] lottery problem (Was Re: (no subject))

Adam Jensen hanzer at riseup.net
Fri Dec 19 05:24:02 CET 2014

On Thu, 18 Dec 2014 20:27:03 -0500
Adam Jensen <hanzer at riseup.net> wrote:

> And to build the 'lines' list (although, this is getting rather ugly):
> >>> lines = [[random.randint(x,x+6) for x in range(1,50,7)] for i in range(7)]

Oops, in the context of the original program this might make more sense if written as:

data = [[random.randint(x,x+6) for x in range(1,50,7)] for i in range(lines)]

Side note: if one were to only import specific functions from a module, would the load time and memory consumption be smaller? Example, is:

from random import randint, seed

smaller and faster than:

import random

Side side note: since 'i' isn't being used, is there a way to loop (within the list comprehension) without the 'i'? For example, to generate three random numbers:

[randint(1,10) for i in range(3)]  # This works. 
[randint(1,10) for range(3)]  # This does not work. 

More information about the Tutor mailing list