How to create three separate lists of values from a Python list of dictionaries where each dictionary has three keys
<p>I am new to Python. My question might come across as simple to experienced developers and coders but I haven't been able to find out an answer to this. </p>

<p>I am retrieving some data through a database query. I have succeeded in organising each row returned by query as a dictionary having three keys and a corresponding value to each key. Essentially, I have organised all rows of data returned by the query into a list of dictionaries.</p>

<p>The list of dictionaries looks somewhat like this:</p>

<pre><code>[
    {'Date': date1, 'price': price1, 'itemnumber': number1},
    {'Date': date2, 'price': price2, 'itemnumber': number2},
    ...
]
</code></pre>

<p>How can I convert this list of dictionaries into three separate lists corresponding to each key i.e. Date, Price and itemnumber?</p>

<p>Thank you for your help. </p>

<pre><code># Defining lists
dates = []
prices = []
item_numbers = []
# Loop through list
for dictionary in your_list:
    dates.append(dictionary["Date"]) # Add the date to dates
    prices.append(dictionary["price"]) # Add the price to prices
    # Add item number to item_numbers
    item_numbers.append(dictionary["itemnumber"])
</code></pre>

python list dictionary