0

I have a bit of code with 6 lists (Group1, Group2, Group3, etc..).

I want to use the sample function to take 4 random items from one of the lists. I want the sample to look like this: sample(Group{0}.format(randrange(6), 4).

But that function doesn't work. Is there anything like this, that works with this situation.

I've tried the .format way, but that doesn't work with. I've search the internet for a answer, but I couldn't find an answer.

Does a similar solution exist?

Possible_Signs0 = ["O", "AT", "Golf", "Hartbeat", "Octopus", "JL", "ReverseC."]
Possible_Signs1 = ["ReverseE..", "O", "ReverseC.", "Oink", "WhiteStar", "JL", "Reverse?"]
Possible_Signs2 = ["Copyright", "WwithEye", "Oink", "b2bK", "RRR", "Golf", "WhiteStar"]
Possible_Signs3 = ["6", "Music", "BwithWings", "Octopus", "b2bK", "Reverse?", "Smiley"]
Possible_Signs4 = ["3tooth", "Smiley", "BwithWings", "C.", "Music", "Shrek3", "BlackStar"]
Possible_Signs5 = ["6", "ReverseE..", "Stitch", "ae", "3Tooth", "H", "Omega"]

Used_signs = sample(Possible_Signs + randrange(6), 4)
print(Used_signs)

It should print a sample from a random Possible_signsN group.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158

1 Answers1

0

You can't really do exactly what you want - see this answer for more details of why.

But if you change your code a little then you could do something similar:

signs_dict = {
    "Possible_Signs1": ["ReverseE..", "O", "ReverseC.", "Oink", "WhiteStar", "JL", "Reverse?"],
    "Possible_Signs2": ["Copyright", "WwithEye", "Oink", "b2bK", "RRR", "Golf", "WhiteStar"],
    "Possible_Signs3": ["6", "Music", "BwithWings", "Octopus", "b2bK", "Reverse?", "Smiley"],
    "Possible_Signs4": ["3tooth", "Smiley", "BwithWings", "C.", "Music", "Shrek3", "BlackStar"],
    "Possible_Signs5": ["6", "ReverseE..", "Stitch", "ae", "3Tooth", "H", "Omega"],
}

mykey = 'Possible_Signs{}'.format(randrange(6))
used_signs = sample(signs_dict[mykey], 4)

print(used_signs)
PyPingu
  • 1,697
  • 1
  • 8
  • 21