Advanced Python Mastery
Something I hate in my own code is this pattern of instantiating an empty list and then iterating on it when reading files. Is there a better way than starting  lst= [] and then later doing lst.append()<p>This is an example from the linked course <a href="https:&#x2F;&#x2F;github.com&#x2F;dabeaz-course&#x2F;python-mastery&#x2F;blob&#x2F;main&#x2F;Exercises&#x2F;ex2_2.md">https:&#x2F;&#x2F;github.com&#x2F;dabeaz-course&#x2F;python-mastery&#x2F;blob&#x2F;main&#x2F;Ex...</a>:<p>```
# readport.py<p>import csv<p># A function that reads a file into a list of dicts<p>def read_portfolio(filename):<p><pre><code>    portfolio = []

    with open(filename) as f:

        rows = csv.reader(f)

        headers = next(rows)

        for row in rows:

            record = {

                &#x27;name&#x27; : row[0],

                &#x27;shares&#x27; : int(row[1]),

                &#x27;price&#x27; : float(row[2])

            }

            portfolio.append(record)

    return portfolio
</code></pre>
```