Use the fromkeys function to initialize a dictionary with any default value. In your case, you will initialize with None since you don't have a default value in mind.

Copyempty_dict = dict.fromkeys(['apple','ball'])

this will initialize empty_dict as:

Copyempty_dict = {'apple': None, 'ball': None}

As an alternative, if you wanted to initialize the dictionary with some default value other than None, you can do:

Copydefault_value = 'xyz'
nonempty_dict = dict.fromkeys(['apple','ball'],default_value)
Answer from codegeek on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ initialize-python-dictionary-with-keys-and-values
Initialize Python Dictionary with Keys and Values - GeeksforGeeks
July 23, 2025 - We will discuss common techniques used to initialize Python dictionaries with keys and values, accompanied by illustrative code examples.
Discussions

How to create a dictionary where the keys have the same name as variable they are assigned?
You don't want *args, you want **kwargs, which will literally give you the dict you want already - nothing else required. More on reddit.com
๐ŸŒ r/learnpython
5
2
December 1, 2022
Initializing dictionaries from a list of key-value pairs

Also good to note that this works for generators. So you can have:

a = range(10)
b = (x**2 for x in range(10))
dict(zip(a, b))

or

a = ((x, x**2) for x in range(10))
dict(a)
More on reddit.com
๐ŸŒ r/pythontips
1
30
November 6, 2016
Can you create a dictionary with a string by mapping the letters to its index?
Yes. But why would you want that? This sounds like an XY problem. We could help a lot more if you told us what problem you are trying to solve, not just how you are trying to solve it. What's the big picture here? http://xyproblem.info More on reddit.com
๐ŸŒ r/learnpython
13
4
February 20, 2023
How to set a default value when a key doesn't exist in a dictionary?

This is the entire purpose of the get() method for dicts.

The method takes two arguments: the first is the key to look for, and the second is the value to return if that key doesn't exist in the dict. (If the key does exist the return value is simply the value associated with that key.)

so my_dict.get("f","Default Value") will do exactly what you're looking for.

Note that this won't actually add the non-existent keys to your dict. If you want to add those keys to your dict you can use defaultdict from the collections module.

https://docs.python.org/3/library/collections.html#defaultdict-objects

More on reddit.com
๐ŸŒ r/learnpython
14
28
July 27, 2024
๐ŸŒ
Medium
sokacoding.medium.com โ€บ 6-ways-to-initialize-a-dictionary-in-python-e9a0b1a5572e
6 Ways to initialize a Dictionary in Python | by sokacoding | Medium
January 24, 2023 - Let us modify the dictionary so we only use key-value pairs where the value of the squared number is bigger than 5. my_numbers = [1, 2, 3, 4] my_dict = {num: num**2 for num in my_numbers if num**2 > 5} print(my_dict) >>> {3: 9, 4: 16} For the sake of completeness, I show you how to use dictionary comprehension if we have a list of tuples with our sample data to initialize a dictionary. Of course, you would use this list within the dict() constructor and be done right away.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_dictionaries.asp
Python Dictionaries
Python Overview Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods Python Tuple Methods Python Set Methods Python File Methods Python Keywords Python Exceptions Python Glossary ยท Built-in Modules Random Module Requests Module Statistics Module Math Module cMath Module ยท Remove List Duplicates Reverse a String Add Two Numbers ยท Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... Dictionaries are used to store data values in key:value pairs.
๐ŸŒ
PhoenixNAP
phoenixnap.com โ€บ home โ€บ kb โ€บ devops and development โ€บ how to initialize dictionary in python
How to Initialize Dictionary in Python
April 1, 2026 - The simplest and most common way to initialize a Python dictionary is to pass key-value pairs as literals in curly braces. For example: my_dictionary = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'} Use this method when working with ...
๐ŸŒ
Namehero
namehero.com โ€บ blog โ€บ how-to-initialize-a-dictionary-in-python
How to Initialize a Dictionary in Python
November 7, 2024 - There are many ways to initialize a dictionary in Python, depending on whether you want to create an empty dictionary or one pre-filled with values that you specify. For example, to just create a new dictionary, we can use: ... The two curly brackets {} signify a dictionary. You can also initialize a dictionary like this: ... The โ€œdict()โ€ function is a constructor that we can use to either create an empty dictionary or one pre-filled with data. For example, we can use it to create a dictionary like this: ... The above dictionary has two items โ€“ name and age. These are โ€œkeysโ€. Each key is associated with a value.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ create-a-dictionary-in-python-python-dict-methods
Create a Dictionary in Python โ€“ Python Dict Methods
March 14, 2022 - A dictionary in Python is made up of key-value pairs. In the two sections that follow you will see two ways of creating a dictionary. The first way is by using a set of curly braces, {}, and the second way is by using the built-in dict() function.
Find elsewhere
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ dictionary-dict-function
Python Dictionary: Syntax and Examples [Python Tutorial]
The syntax to create a new dictionary in Python requires curly braces ({}). Within the curly braces, you add key-value pairs with a colon in between. After each key-value pair, you add a comma (except after the last key-value pair). ... You can create (or initialize) an empty dictionary by ...
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ how to initialize dictionary in python โ€“ a step-by-step guide
How to Initialize Dictionary in Python - A Step-By-Step Guide - AskPython
September 24, 2022 - We can define or initialize our dictionary using different methods in python as follows. We can create a dictionary by passing key-value pairs as literals. The syntax for passing literals is given below following an appropriate example. ...
๐ŸŒ
Index.dev
index.dev โ€บ blog โ€บ initialize-dictionary-with-empty-lists-python
How to Initialize a Dictionary with Empty Lists in Python [with Examples]
The dict.fromkeys() method can initialize a dictionary with specified keys, and you can provide a default value for each key, such as an empty list.
๐ŸŒ
Pydantic
docs.pydantic.dev โ€บ latest โ€บ concepts โ€บ models
Models | Pydantic Docs
Pydantic can validate data in three different modes: Python, JSON and strings. ... The __init__() model constructor. Field values must be provided using keyword arguments. model_validate(): data can be provided either as a dictionary, or as a model instance (by default, instances are assumed ...
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ reference โ€บ datamodel.html
3. Data model โ€” Python 3.14.6 documentation
If a dictionary is used to assign __slots__, the dictionary keys will be used as the slot names. The values of the dictionary can be used to provide per-attribute docstrings that will be recognised by inspect.getdoc() and displayed in the output of help(). __class__ assignment works only if both classes have the same __slots__. Multiple inheritance with multiple slotted parent classes can be used, but only one parent is allowed to have attributes created by slots (the other bases must have empty slot layouts) - violations raise TypeError.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_variables_multiple.asp
Python Variables - Assign Multiple Values
Python Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercises Code Challenge Python If...Else
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_sets.asp
Python Sets
Set is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Tuple, and Dictionary, all with different qualities and usage. A set is a collection which is unordered, unchangeable*, and unindexed. * Note: Set items are unchangeable, but you can remove items and add new items. Sets are written with curly brackets. ... Note: Sets are unordered, so you cannot be sure in which order the items will appear. Set items are unordered, unchangeable, and do not allow duplicate values.
๐ŸŒ
Hexlet
hexlet.io โ€บ home
Theory: Initializing new values and defaultdicts - Hexlet
Browse 500+ free and paid programming courses at Hexlet. Python, JavaScript, Java, PHP, Go, DevOps, Testing. Practice in browser, tutor feedback.
๐ŸŒ
DataCamp
datacamp.com โ€บ blog โ€บ top-python-interview-questions-and-answers
The 41 Top Python Interview Questions & Answers For 2026 | DataCamp
April 30, 2026 - The collections module in Python provides specialized data structures like defaultdict, Counter, deque, and OrderedDict to simplify various tasks. For instance, Counter is ideal for counting elements in an iterable, while defaultdict can initialize dictionary values without explicit checks.
๐ŸŒ
Learn X in Y Minutes
learnxinyminutes.com โ€บ python
Learn Python in Y Minutes
Note - Same as above regarding ... from a dictionary with del del filled_dict["one"] # Removes the key "one" from filled dict # From Python 3.5 you can also use the additional unpacking options {"a": 1, **{"b": 2}} # => {'a': 1, 'b': 2} {"a": 1, **{"a": 2}} # => {'a': 2} # Sets store ... well sets empty_set = set() # Initialize a set with a bunch of values...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-initialize-dictionary-in-python
How to Initialize Dictionary in Python - GeeksforGeeks
July 23, 2025 - The simplest and most efficient method to initialize a dictionary is using curly braces {}. This is the easiest and most common way to create a dictionary. We can use curly braces '{} ' and separate the keys and values with : colon.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ functions.html
Built-in Functions โ€” Python 3.14.6 documentation
The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set). CPython implementation detail: len raises OverflowError on lengths larger than sys.maxsize, such as range(2 ** 100). ... Rather than being a function, list is actually a mutable sequence type, as documented in Lists and Sequence Types โ€” list, tuple, range. ... Return a mapping object representing the current local symbol table, with variable names as the keys, and their currently bound references as the values.
๐ŸŒ
Godot Engine
docs.godotengine.org โ€บ en โ€บ 4.4 โ€บ classes โ€บ class_dictionary.html
Dictionary โ€” Godot Engine (4.4) documentation in English
A built-in data structure that holds key-value pairs. Description: Dictionaries are associative containers that contain values referenced by unique keys. Dictionaries will preserve the insertion or...