Shuffle

Dave Angel davea at davea.name
Mon Sep 15 15:32:34 CEST 2014


Michael Torrie <torriem at gmail.com> Wrote in message:
> On 09/13/2014 05:47 PM, Seymore4Head wrote:
>> Here is a screenshot of me trying Dave Briccetti's quiz program from
>> the shell and it (the shuffle command) works.
>> https://www.youtube.com/watch?v=VR-yNEpGk3g
>> http://i.imgur.com/vlpVa5i.jpg
>> 
>> Two questions
>> If you import random, do you need to "from random import shuffle"?
>> 
>> Why does shuffle work from the command line and not when I add it to
>> this program?
>> 
>> import random
>> import shuffle
>> nums=list(range(1,11))
>> shuffle(nums)
>> print (nums)
>> 
>> I get:
>> No module named 'shuffle'
> 
> You can do it two ways:
> Refer to it as random.shuffle()
> 
> or
> 
> from random import shuffle
> 
> I tend to use the first method (random.shuffle).  That way it prevents
> my local namespace from getting polluted with random symbols imported
> from modules.
> 
> 

Or a third way:

import random
shuffle = random.shuffle


-- 
DaveA




More information about the Python-list mailing list