kal kal - 1 year ago 104
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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download