dict.fromkeys directly solves the problem:

Copy>>> dict.fromkeys([1, 2, 3, 4])
{1: None, 2: None, 3: None, 4: None}

This is actually a classmethod, so it works for dict-subclasses (like collections.defaultdict) as well.

The optional second argument, which defaults to None, specifies the value to use for the keys. Note that the same object will be used for each key, which can cause problems with mutable values:

Copy>>> x = dict.fromkeys([1, 2, 3, 4], [])
>>> x[1].append('test')
>>> x
{1: ['test'], 2: ['test'], 3: ['test'], 4: ['test']}

If this is unacceptable, see How can I initialize a dictionary whose values are distinct empty lists? for a workaround.

Answer from Thomas Wouters on Stack Overflow
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ empty-dictionary-python
Create Empty Dictionary in Python (5 Easy Ways) | FavTutor
April 13, 2022 - To create an empty dictionary in this example, we can use a dict(), which takes no arguments. If no arguments are provided, an empty dictionary is created. ... In Python, we can use the zip() and len() methods to create an empty dictionary with keys.
Discussions

Adding Key: Value to Empty Dictionary via For Loop
dictionary keys are "unique" - so you are overwriting the previous entry each time. >>> quotes = {} >>> quotes['author'] = 'quote1' >>> quotes {'author': 'quote1'} >>> quotes['author'] = 'quote2' >>> quotes {'author': 'quote2'} Perhaps you want a list of dicts? [ { 'author': 'quote1' }, { 'author': 'quote2' }, ... ] More on reddit.com
๐ŸŒ r/learnpython
6
1
December 3, 2022
How to declare an empty dictionary of empty dictionaries in Python 2.7? - Stack Overflow
To declare an empty dictionary, I do: mydict = dict() To declare an empty dictionary of empty dictionaries, I can do also: mydictofdict = dict() Then add dictionaries when needed: mydict1 = dict() More on stackoverflow.com
๐ŸŒ stackoverflow.com
"Which creates an empty dictionary?"
An empty dictionary is a data structure that can store key-value pairs but starts with no data. It is created using the syntax dict() or {} in Python. More on testbook.com
๐ŸŒ testbook.com
1
1501
3 weeks ago
How can I remove keys in a dictionary where the value is empty?
Create a new dictionary: myDict = {key: value for key, value in myDict if value} More on reddit.com
๐ŸŒ r/learnpython
14
18
February 25, 2021
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ how to create python empty dictionary?
How to Create Python Empty Dictionary? - Spark By {Examples}
May 31, 2024 - You can use the zip() and len() methods to create an empty dictionary with keys and no values. Python zip() is a built-in function that is used to zip or combine the elements from two or more iterable objects like lists, tuples, dictionaries, etc.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ adding key: value to empty dictionary via for loop
r/learnpython on Reddit: Adding Key: Value to Empty Dictionary via For Loop
December 3, 2022 -

Over the years I've collected a lot of quotes and I am trying to write a script to parse them out into a dictionary so I can use them in another script.

The quotes are always in this format:

> [!quote] Quote by [[Robert Greene]]
> Cultivate a fearless approach to life, attack everything with boldness and energy.

So I've created this script to get them and add them to a dictionary:

import re

quote_list = {}

with open('Quotes.md', 'r', encoding='UTF8') as file:
    for line in file:
        if '[!quote]' in line:
            author = re.findall(r'\[\[(.*?)]]', line) # Find [[author]]
            author = ' '.join(author) # remove []
            quote_list['author'] = author # add to dictionary
        elif '>' in line and not '[!quote]' in line:
            quote = line.strip('> ').strip('\n') # strip off > and \n
            quote_list['quote'] = quote

print(quote_list)

However, the final result is only 1 quote (the last quote in the document), so it appears to be overwriting the entry each time. I'm at a loss for what I'm doing wrong so any advice is much appreciated.

As I typed this out I realized that I don't think this is going to keep the authors + quotes together like I had hoped.

Example:

{'author': 'Frank A. Clark', 'quote': "We find comfort among those who agree with us - growth among those who don't"}

Update: This is the final solution I landed on. Reading line by line, if the line meets my criteria then I do what I need to for the author and then use next(file) to skip to the next line and pull the quote, finally adding it into a list as a separate dictionary.

https://pastebin.com/nuiT8Nry

๐ŸŒ
Python Guides
pythonguides.com โ€บ how-to-create-an-empty-python-dictionary
Create an Empty Dictionary in Python
September 9, 2025 - ... I often start with curly braces when I know Iโ€™ll be adding values dynamically. Itโ€™s quick, clean, and a common way to create an empty dictionary is by using curly braces. # Creating an empty dictionary using curly braces employee_data = {} # Example: adding key-value pairs later ...
๐ŸŒ
EyeHunts
tutorial.eyehunts.com โ€บ home โ€บ python create empty dictionary with keys | example code
Python create empty dictionary with keys | Example Code - EyeHunts
February 25, 2022 - Use dict.fromkeys() to create an empty dictionary with keys to an empty value in Python. You can use the dict fromkeys method or dict-compre
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ initialize-an-empty-dictionary-in-python
Initialize an Empty Dictionary in Python - GeeksforGeeks
July 15, 2025 - To initialize an empty dictionary in Python, we need to create a data structure that allows us to store key-value pairs. Different ways to create an Empty Dictionary are: ... We can create an empty dictionary object by giving no elements in ...
Find elsewhere
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ create-a-dictionary-in-python-python-dict-methods
Create a Dictionary in Python โ€“ Python Dict Methods
March 14, 2022 - First, specify the name of the dictionary. Then, in square brackets, create a key and assign it a value. Say you are starting out with an empty dictionary:
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-initializing-dictionary-with-empty-lists
Initializing dictionary with Empty Lists in Python - GeeksforGeeks
July 11, 2025 - Dictionary comprehension is the most sought method to do this initialization. In this method, we create the no. of keys we require and then initialize the empty list as we keep on creating the keys, to facilitate the append operation afterward without an error. ... # Python3 code to demonstrate # to initialize dictionary with list # using dictionary comprehension # using dictionary comprehension to construct new_dict = {new_list: [] for new_list in range(4)} # printing result print ("New dictionary with empty lists as keys : " + str(new_dict))
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ How-to-create-an-empty-dictionary-in-Python
How to create an empty dictionary in Python?
May 15, 2023 - Following is the syntax for creating the empty dictionary. ... dict1 = dict() print("Contents of the dictionary: ",dict1) dict1['colors'] = ["Blue","Green","Red"] print("Contents after inserting values: ",dict1) Contents of the dictionary: {} Contents after inserting values: {'colors': ['Blue', 'Green', 'Red']} ... dict1 = dict() print("Contents of the dictionary: ",dict1) dict1['Language'] = ["Python","Java","C"] dict1['Year'] = ['2000','2020','2001'] print("Contents after adding key-value pairs: ",dict1)
๐ŸŒ
Index.dev
index.dev โ€บ blog โ€บ initialize-dictionary-with-empty-lists-python
How to Initialize a Dictionary with Empty Lists in Python [with Examples]
def initialize_dict_with_empty_lists(keys): return {key: [] for key in keys} keys = ['a', 'b', 'c'] dict_with_empty_lists = initialize_dict_with_empty_lists(keys) print(dict_with_empty_lists) ... Ideal for scenarios where dictionary initialization is part of a larger application or module. By using a function, you can easily reuse the initialization logic across different parts of your codebase, enhancing modularity and maintainability. ... Initializing a dictionary with empty lists in Python is a common requirement for many data handling and aggregation tasks.
๐ŸŒ
datagy
datagy.io โ€บ home โ€บ python posts โ€บ python: check if a dictionary is empty (5 ways!)
Python: Check if a Dictionary is Empty (5 Ways!) โ€ข datagy
December 20, 2022 - In the next section, youโ€™ll learn how to check if a dictionary is empty by checking its length. Want to learn how to do a VLOOKUP in Pandas? The trick is to use dictionaries! Learn how to do this in this in-depth tutorial with practical, follow-along examples. Python dictionaries allow us to check their length, i.e., the number of keys the have, by using the built-in len() function.
Top answer
1 of 1
2101
"The correct answer is dict(). Key Points dict() is a built-in Python function used to create an empty dictionary. An empty dictionary is a data structure that can store key-value pairs but starts with no data. It is created using the syntax dict() or {} in Python. Dictionaries are mutable, meaning you can add, update, or delete key-value pairs after creation. They are widely used in Python programming for various purposes like data organization and quick lookups. Additional Information Other Options: []: This creates an empty list, not a dictionary. {}: This also creates an empty dictionary in Python, similar to dict(). set(): This creates an empty set, not a dictionary. empty_dict(): This is not a valid Python function for creating an empty dictionary. Examples of Creating Dictionaries: Empty Dictionary: my_dict = dict() or my_dict = {} Dictionary with Data: my_dict = {key1: value1, key2: value2} Advantages of Using Dictionaries: Allow for fast lookups by keys, making them ideal for storing and retrieving data quickly. Support various data types for keys and values, providing flexibility. Enable easy data manipulation, such as adding or removing items. Important Points: Dictionaries are unordered prior to Python 3.7, but they maintain insertion order in Python 3.7 and later. Keys in a dictionary must be immutable and unique, while values can be of any type and duplicated. Using appropriate keys and values is essential for efficient and effective dictionary usage."
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-initialize-a-dictionary-with-only-keys-from-a-list
Initialize a Dictionary with Only Keys from a List - Python - GeeksforGeeks
July 11, 2025 - ... Explanation: {key: None for key in li} loops over each element in li, uses each element as a dictionary key and assigns None as the corresponding value. This process results in a new dictionary with the keys from the list and None as their ...
๐ŸŒ
Quora
quora.com โ€บ How-do-I-create-an-empty-dictionary-in-Python
How to create an empty dictionary in Python - Quora
Answer (1 of 13): * In Python to create an empty dictionary, we can assign no elements in curly brackets {}. * We can also create an empty dictionary by using the dict () method it is a built-in function in Python and takes no arguments.
๐ŸŒ
PhoenixNAP
phoenixnap.com โ€บ home โ€บ kb โ€บ devops and development โ€บ how to initialize dictionary in python
How to Initialize Dictionary in Python
April 1, 2026 - For example, append a new key-value pair using the assignment operator to append the data to the initialized empty dictionary. ... After reading this guide, you know several different ways to initialize a Python dictionary.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ dictionary-dict-function
Python Dictionary: Syntax and Examples [Python Tutorial]
You can also create a dictionary using the dict() function and passing key-value pairs as keyword arguments. Using dict() without any arguments creates an empty dictionary.
๐ŸŒ
CodeGenes
codegenes.net โ€บ blog โ€บ how-to-create-an-empty-dictionary-in-python
Creating an Empty Dictionary in Python: A Comprehensive Guide โ€” codegenes.net
Here is an example: ... This code ... example, i.e., {}. Once you have an empty dictionary, you can add key-value pairs to it using the assignment operator....