Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #77887

Re: Shuffle

From Dave Angel <davea@davea.name>
Subject Re: Shuffle
Date 2014-09-15 09:32 -0400
Organization news.gmane.org
References <ruk91al1vliuf3uobq1e0el2hrp61p6uf5@4ax.com> <5414F047.9030809@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.14027.1410788105.18130.python-list@python.org> (permalink)

Show all headers | View raw


Michael Torrie <torriem@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Shuffle Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-13 19:47 -0400
  Re: Shuffle Chris Angelico <rosuav@gmail.com> - 2014-09-14 10:28 +1000
  Re: Shuffle Michael Torrie <torriem@gmail.com> - 2014-09-13 19:32 -0600
    Re: Shuffle Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-13 22:10 -0400
  Re: Shuffle Dave Angel <davea@davea.name> - 2014-09-15 09:32 -0400
    Re: Shuffle Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-16 00:02 +1000
      __import__(name, fromlist=...), was Re: Shuffle Peter Otten <__peter__@web.de> - 2014-09-15 16:30 +0200

csiph-web