Search for element in list of list Python
<p>New to programming.
I'm trying to create a program that has a list o list (As a data base) the first element being an invoice, the second the value of that invoice and the third, the margin of income. Given an invoice (input), it will search within the list o lists(data base).</p>

<p>I currently have:</p>

<pre><code>Data_base= [["f1",2000,.24],["f2",150000,.32],["f3",345000,.32]]
invoice = input("Enter invoice: ")

if invoice in data_base :
    print ("Invoice is valid")

else :
    print("Invoice does not exist, enter a valid document: ")
</code></pre>

<p>When I run the program and I enter a valid element within the list, it does not recognize as an element within the list.</p>

<p>What am I doing wrong?</p>

<p>What is the code to be given the index if the element is within the list of lists?</p>

<p>Here's the solution I found:</p>

<pre><code>data_base = [["f1",2000,.24],["f2",150000,.32],["f3",345000,.32]]
invoice = input("Enter invoice: ")

found = False

for data in data_base:
    if invoice == data[0]:
        found = True
        break

result = "Invoice is valid" if found else "Invoice does not exist, enter a valid document: "

print(result)
</code></pre>

<p>First you should iterate in all <code>data_base</code> elements and then check if the first element is the invoice you're looking for.</p>

python list search element