Python, search list of list and give next value
<p>I'm creating a program that given a percentage for commission and given an invoice(s), it will look for given invoices, look for the value of that invoice and calculate the commission based on the percentage input. When we input <code>"calculate"</code> it will sum all the commission and give me the total of commission. </p>

<p>I'm having trouble trying to identify the input within the list. Once I do that, what must I do to be given the value of that invoice?</p>

<p><code>data base = [Invoice, Invoice amount, invoice margin]</code></p>

<p>This is what I have so far. </p>

<pre><code>data_base = [["f1",2000,.24],["f2",150000,.32],["f3",345000,.32]]
comission_percentage = int(input("Comision Percentage: "))
invoice = input("Enter an invoice: ")
total_comision = 0


while invoice != "calculate" :
    while invoice in data_base:
        invoice_ = data_base.index(invoice)+1 #Gives me the position of invoice
        invoice_amount = data_base[p_factura] #Give me the value os the invoice
        comission = ((margen_comisionar/100)* monto_factura) #calculatecomission
        total_comision = comission + total_comission         
        invoice = input("Enter an invoice: ")
print("The amount to comission is: " + str(total_comission))
</code></pre>

<p>Your 'database' seems to be a list of lists.  I'm assuming the input from the user is supposed to match the first part of the list.</p>

<p>So given:</p>

<pre><code>data_base = [["f1",2000,.24],["f2",150000,.32],["f3",345000,.32]]
</code></pre>

<p>If the user inputs <code>f1</code>, you want it to match <code>["f1",2000,.24]</code>.</p>

<p>Your inner <code>while</code> loop will not work in this case since <code>"f1"</code> is not in <code>[["f1",2000,.24],["f2",150000,.32],["f3",345000,.32]]</code></p>

<p>You need to check if the first element of every element of your list matches your input.</p>

<pre><code>for invoice_info in database:
    if invoice in invoice_info:
       # found it!
       &lt;do your invoice commission calculations here&gt;
</code></pre>

<p>A better way to do it would be to convert your database to dictionaries:</p>

<pre><code>data_base = {'f1': {'invoice_amount': 2000, 'invoice_margin': .24},
             'f2': {'invoice_amount': 15000, 'invoice_margin': .32},
             'f3': {'invoice_amount': 345000, 'invoice_margin': .32}
             }
</code></pre>

<p>Then you can do</p>

<pre><code>if invoice in data_base:
    found_invoice = data_base[invoice]
    total_commission += found_invoice['invoice_amount'] * commission_percentage / 100
</code></pre>

python list element