im trying to the below code but when I run the function for examnple:
finder(“001-987654-003”)
Nothing is happening. What went wrong?
def finder(lookupvalue): user_list = [ ["Account number","Currency","Balance"], ["001-987654-003","USD",1300.72], ["001-919202-100","EUR",105.01], ["001-905700-100","EUR",305.00], ["001-908415-307","CHF",20804.98], ["011-974777-200","PLN",208.15], ["001-931654-001","USD",450.7] ] for row in user_list: if user_list[0][0]==lookupvalue: print("yes")
Advertisement
Answer
try this:
user_list = [ ["Account number", "Currency", "Balance"], ["001-987654-003", "USD", 1300.72], ["001-919202-100", "EUR", 105.01], ["001-905700-100", "EUR", 305.00], ["001-908415-307", "CHF", 20804.98], ["011-974777-200", "PLN", 208.15], ["001-931654-001", "USD", 450.7] ] def finder(lookupvalue, lookuplist, col_index): for row in user_list: if row[0] == lookupvalue: print(row[col_index-1]) finder("001-919202-100", user_list, 2)
output:
EUR