New to python so apologies if this is trivial. I have a list
list = [3,1,0,2]
and a nested lookup
lookup = [[265,301,201],[225,302,191],[225,35,134],[28,82,158]]
I need to match every element in "list" with each corresponding element index in "lookup" and return the value of this element from "lookup". The result should be:
result = [
[28,82,158],
[225,302,191],
[265,301,201],
[225,35,134]
]
You can use a list comprehension:
result = [lookup[i] for i in list]
(Note that you shouldn't call a variable list. It will shadow the builtin of the same name, and will lead to unexpected beahaviour sooner or later.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With