Python

Nemphis

Excellent OT User
Joined
Jun 22, 2009
Messages
340
Best answers
0
Reaction score
117
Location
Sweden
I apologise for asking, but i started Learning Python and i need to do a disctionary/list -thing like we do in LUA. But i cant seem to find out how to do it.

What i want it something similiar to this.
Code:
import random

input = random.randint(1, 2)

list = {
    [1] = {first = 1, second = 2, third = 3, forth = 4}
    [2] = {first = 10, second = 20, third = 30, forth = 40}
}

theList = list[input]
I've searched on Youtube and Learning websites, but i cant seem to find any.

Anyone knows on how I can do it in Python 3.x?
 

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
4,905
Best answers
446
Reaction score
2,517
Avoid naming your variables things like "input" and "list", those are both python functions and you are overriding them.
Keep in mind lists start from 0 not 1.
Python:
import random

selection = [
    {'first': 1, 'second': 2, 'third': 3, 'forth': 4},
    {'first': 10, 'second': 20, 'third': 30, 'forth': 40}
]

selected = random.choice(selection) # or selection[random.randint(0, len(selection) - 1)]

print(selected)
 
OP
Nemphis

Nemphis

Excellent OT User
Joined
Jun 22, 2009
Messages
340
Best answers
0
Reaction score
117
Location
Sweden
thank you. it helped more than most sites
 
Top