how transform my elements into a dictionnary

Viewed 45

I try to do some templates and I need to create something like that:

issuer: QualityHosting AG
fields:
  amount: Total EUR\s+(\d+,\d+)
  amount_untaxed: Total EUR\s+(\d+,\d+)
  date:
    - \s{2,}(\d+\. .+ \d{4})\s{2,}
    - Rechnungsdatum\s+(\w+ \d+, \d{4})
  invoice_number: Rechnungsnr\.\s+(\d{8})

Its not a problem with the regex but with the dict; how can I have fields:amount:

there is my code but I don't think its a correct way

   
    issuer = request.form['issuer']
    amount = request.form['amount']
    amount_untaxed = request.form['amount_untaxed']
    date =  request.form['date']
    invoice_number = request.form['invoice_number']
    start= request.form['start']
    keyword= request.form['keyword']
    print(issuer, amount,date, amount_untaxed, invoice_number, start, keyword)

    di={
        "issuer": issuer,
        "fields" : {
        "amount": amount,
        "amount": "1964",
        "date": date
        }
    }
    print(di.fiel)

I searched on tutorials but it was not exactly this.

1 Answers

First, the keys of a dictionary must be unique, so you can't have 2 amount as key.

Second, to get the key value you use the function get(key_value)

di={
    "issuer": 'issuer',
    "fields" : {
    "amount1": 'amount',
    "amount2": "1964",
    "date": 'date'
    }
}
print(di.get("fields"))
# {'amount1': 'amount', 'amount2': '1964', 'date': 'date'}
Related