tips for this exercise?

John Salerno johnjsal at NOSPAMgmail.com
Tue Mar 28 22:32:32 CEST 2006


Brian Quinlan wrote:

> I would just write the function like this:
> 
> def genNumbers():
>     shuffle_nums = numbers[:]    # copy the list to preserve the orginal
>                                  # order (if it matters)
>     random.shuffle(shuffle_nums) # shuffle the entire list
>     return shuffle_nums[:5]      # return the first 5 elements

Thanks. Interesting idea. I did consider copying it, but does that hurt 
performance each time the function is called? I know it may not be 
noticeable, but I don't like the idea of doing unnecessary work like 
that, if it is in fact unnecessary.



More information about the Python-list mailing list