The Artima Developer Community
Sponsored Link

Python Answers Forum
random from an array

3 replies on 1 page. Most recent reply: Aug 7, 2004 8:10 PM by Chris Dutton

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Calvin

Posts: 3
Nickname: calvin79
Registered: Aug, 2004

random from an array Posted: Aug 6, 2004 3:08 PM
Reply to this message Reply
Advertisement
Hi All,

I've just started to try python so forgive the ignorance!

I've been using this, or something like it;

First = random.choice ('abc')
answer = first
print answer - no problems there.

What I want to do, however, is take a random pick from something like the following;

First = random.??? ("rna", "rnb", "rnc") - this of course "random.choice" doesn't work.

Could some kind person help me out with the code? I know I'm trying to run before I can walk, but there you go...

Thanks,

Calvin


Chris Dutton

Posts: 15
Nickname: cdutton
Registered: Jul, 2004

Re: random from an array Posted: Aug 7, 2004 12:53 PM
Reply to this message Reply
first = random.choice(["ma", "mb", "mc"])

Calvin

Posts: 3
Nickname: calvin79
Registered: Aug, 2004

Re: random from an array Posted: Aug 7, 2004 5:48 PM
Reply to this message Reply
Thanks Chris, that's great!

Chris Dutton

Posts: 15
Nickname: cdutton
Registered: Jul, 2004

Re: random from an array Posted: Aug 7, 2004 8:10 PM
Reply to this message Reply
No problem.

Flat View: This topic has 3 replies on 1 page
Topic: Playing with decorators Previous Topic   Next Topic Topic: forget my other post, read this one

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use