Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7177527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:43:57+00:00 2026-05-28T16:43:57+00:00

Is there a way to pass a variable to the choice() function for a

  • 0

Is there a way to pass a variable to the choice() function for a list. I have a bunch of lists and I want to randomly select from one list and then use the string that is returned to select from a list that has that string name.

A = ['1','2','3']

print choice (A) - this gets me a random choice from the list

but I want to to store the choice as a variable and use it to call another list

A = ['1','2','3']
1 = ['A','B','C']

Var1 = choice (A)

print choice (Var1) *** this is my problem, how do I pass a variable to the choice function

Thanks for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:43:59+00:00Added an answer on May 28, 2026 at 4:43 pm

    In Python, you can do this using references.

    A = [1, 2, 3]
    B = [4, 5, 6]
    C = [7, 8, 9]
    MasterList = [A, B, C]
    
    whichList = choice(MasterList)
    print choice(whichList)
    

    Note that A, B, C are names of previously assigned variables, instead of quoted strings. If you ever find yourself using quoted names to refer to variables, there’s usually a better way to do whatever you’re trying to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to directly pass a variable number of arguments from one
Is there a way I can pass a PHP variable from a PHP page
As the title says, is there another way to pass a variable from "current"
Is there any way to pass a variable from the suite to the test
Is there a way to pass a variable into a regex in jQuery/Javascript? I
I am wondering if there is a way to pass a variable to a
Is there a way to pass a call back function in a Java method?
Is there any way to pass a callback to java code, from C. And
Is there a way to pass a variable to twitter when you authorized and
Is there a way to pass the DatePart parameter of DateDiff as a variable?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.