Reputation: 21
I am trying to build a function, which should accept the parameter and return the value by filtering an array by iterating it's value. I start to get some what looping the values.
But do not know how to declare the function and get return value from the array. not able to get some suitable online reference.
code:
lst = [["a", 45], ["b", 40], ["c", 18], ["d", 17]]
for x in range(len(lst)):
if lst[x][0] == input("Enter your name:"):
print("Searching in list")
print("name:", lst[x][0], "age:", lst[x][1])
expecting:
getValue(){
findvalue = ("name:", lst[x][0], "age:", lst[x][1])
return findvalue
}
value = getValue(value)
Upvotes: 2
Views: 40
Reputation: 4368
What I have done :
name
) before the loop, so it does not ask at each iterationitem
) instead of its indiceslst = [["a", 45], ["b", 40], ["c", 18], ["d", 17]]
name = input("Enter your name:")
print("Searching in list")
for item in lst:
if item[0] == name:
print("name:", item[0], "age:", item[1])
Upvotes: 1