kal kal - 6 months ago 35
Python Question

Python, matching two list's elements

x= [0,2,3,5,6];
y= [64,384,1024,4096,384];

The above are two arrays I'm using. Im trying to match the elements together in a pythonic way


is 2 i want to compute a variable called
to correspond to its value(position wise) in y. so i should get
y = 384
. if
xType = 3
i should get 1024.

How would i go about doing this


This is so short, even Stack Overflow did not allow me to submit such a short answer:


This will return element from y corresponding to the position of 2 or any other given value from within x list.

Hope it helped :)

Ps. Indeed dictionaries may be something you need. Try using them.