Search code examples
pythonlookup

LOOKUP function in python


i'm kinda new to Python and i'm trying to create my very first program. I decided to make something like FX values (for example EUR/USD). So I created a list, e.g. FX_list = ("12/31/2022", 1.0666). Index [0] is representing date of FX rate, floating number[1] is it's value. My question is, if i can make a function, where i input the string which represents date and in return i get the index 1? It is supposed to work like "vlookup" or "xlookup" in Excel. Thanks for help :)

As i typed above, i'm expecting that the function will lookup the date from list and in return i get the value. List = (x,y) .. lookup x, return y


Solution

  • Try dictionary.

    FX_list = {"12/31/2022" : 1.0666}
    

    And then

    FX_list.get("12/31/2022")
    

    or loop through

    FX_list.keys