-1

I know how to append and access random data from a list. I'm trying to randomize one of the Lists (A, B, or C), then use data from those lists.

Is it as simple as changing random_list to match the actual List_A (or b/c)? Or am I going about it all wrong?

import random

All_Lists = ["List_A", "List_B", "List_C"]
List_A = ["Albert", "Apple", "3", "Alpaca", "4"]
List_B = ["Barbara", "Banana", "6", "Baboon", "3"]
List_C = ["Calvin", "Carrot", "1", "Cat", "0"]

rand_idy = int(random.random() * len(All_Lists))
random_list = All_Lists[rand_idy]
print(random_list)
Peter O.
  • 32,158
  • 14
  • 82
  • 96
majofa
  • 1
  • 2

1 Answers1

0

Change All_Lists as follows, and move it to after the other lists:

All_Lists = [List_A, List_B, List_C]

Note the lack of quotation marks.

In general, you don't reference Python variables by strings that name them. See also: How do I create variable variables?

Peter O.
  • 32,158
  • 14
  • 82
  • 96