That's a dict comprehension.

It is just like a list comprehension

 [3*x for x in range(5)]
 --> [0,3,6,9,12]

except:

{x:(3*x) for x in range(5)}
---> { 0:0, 1:3, 2:6, 3:9, 4:12 }
  • produces a Python dictionary, not a list
  • uses curly braces {} not square braces []
  • defines key:value pairs based on the iteration through a list

In your case the keys are coming from the Code property of each element and the value is always set to empty array []

The code you posted:

order.messages = {c.Code:[] for c in child_orders}

is equivalent to this code:

order.messages = {}
for c in child_orders:
    order.messages[c.Code] = []

See also:

  • PEP0274
  • Python Dictionary Comprehension
Answer from Paul on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › for loops with curly brackets -- please explain
r/learnpython on Reddit: For Loops with Curly Brackets -- Please explain
May 22, 2018 -

I am trying to understand this code. I understand that first for loop is iterating over the comments using the message column. However, why is a second for loop required and what do the curly braces do?

   for comment in comments[' Message']:
               s = sentiment.polarity_scores(comment)
               for k in sorted(s):
               print('{0}: {1}, '.format(k,s[k]))
   print(comment)
Discussions

What do [] brackets in a for loop in python mean? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
python - What is the meaning of a for loop in curly braces? - Stack Overflow
Curly braces are also used for sets. This is a set comprehension. It creates the set of 20 requests.get objects, keeping only the unique ones. If you use [] instead of {} it is a list comprehension. They are similar, but have two differences ... Also, as you mention, this is a bad way to make requests. Comprehensions should be used for creating a list/set, not for calling a number of commands as a by-product. In that case, a simple for-loop ... More on stackoverflow.com
🌐 stackoverflow.com
How does python know where the end of a for-loop code block is? There's no indication of when execution should restart.
I can't use "continue" or "break" because the code block should execute for each item, and then break when no further items are available. The code block in a for loop (in python) has no curly braces nor an "end" keyword indicating the point where the block terminates. More on teamtreehouse.com
🌐 teamtreehouse.com
1
February 3, 2017
Is it true that I can't use curly braces in Python? - Stack Overflow
In fact, Python supports curly braces, BEGIN/END, and almost any other language's block schemes: see python.org/doc/humor/…! ... "No question is newbie enough" (quote from SO FAQ). SO is about questions that can be answered. I believe both are true here. Perhaps for Pythoneers this is a trivial ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Codecademy
codecademy.com › forum_questions › 4f47dd4f6480a60003020e0d
1.5 - Are curly braces {} not necessary in for loops? | Codecademy
I noticed in the pre-written code, there is a statement that reads: for(i=2; i*less than or*=12;i++) newArray[i] = 0; To this point...
🌐
Python Forum
python-forum.io › Thread-No-curly-braces-in-python
No curly braces in python?
August 25, 2017 - Hi everyone. I'm brand new to python. I'm used to the Java programming language, which has opening and closing curly braces marking exactly where the beginning and end of loops and functions are, but so far it appears that Python doesn't use curly br...
🌐
Reuven Lerner
lerner.co.il › home › blog › python › python parentheses primer
Python parentheses primer — Reuven Lerner
November 10, 2022 - The square brackets tell Python that this is a list comprehension, producing a list. If you use curly braces, you’ll get either a set or a dict back, and if you use regular parentheses, you’ll get a generator expression (see above).
Find elsewhere
🌐
Edlitera
edlitera.com › blog › posts › python-parentheses
Python Parentheses Cheat Sheet | Edlitera
Of course, you can always create dictionaries using the dict() method, but that way of creating dictionaries is not used very often. Using curly braces is also faster than invoking dict(), because curly braces are a part of Python's syntax and do not require a function call.
🌐
GeeksforGeeks
geeksforgeeks.org › python › parentheses-square-brackets-and-curly-braces-in-python
Parentheses, Square Brackets and Curly Braces in Python - GeeksforGeeks
July 26, 2025 - 2. Sets: Curly braces are also used to create sets, which are unordered collections of unique elements. For example, my_set = {1, 2, 3, 3, 4}. ... Note: To create empy sets in python use set(), my_set = {} will be an empty dictionary.
🌐
GitHub
github.com › thehackerwithin › PyTrieste › wiki › Python3-FlowControl
Python3 FlowControl
February 21, 2012 - In C/C++ you delimit blocks with curly braces. Python uses ''indentation'' to delimit code blocks. The indentation above is NOT just to make things look pretty - it tells Python what the body of the if-statement is. This is true when ever we create any code blocks, such as the bodies of loops, ...
Author   thehackerwithin
🌐
Plain English
python.plainenglish.io › pythons-brackets-parentheses-and-curly-braces-60cdc236cdd6
Python’s Brackets, Parentheses, and Curly Braces | by Emmanuel Adebanjo | Python in Plain English
August 22, 2023 - Brackets — [], parentheses — (), & curly braces — {} are fundamental concepts that should be understood when dealing with the Python…
🌐
Quora
quora.com › What-does-a-for-loop-without-curly-braces-do
What does a for loop without curly braces do? - Quora
Answer (1 of 6): The curly braces is actually talking about scope. For..loop.. can be used without curly braces if the statement you want to loop consists of only one line of code. Consider the sample code below. [code]for ( int i = 0 ; i
🌐
Processing
py.processing.org › reference › curlybraces
{} (Curly braces) \ Language (API)
Python Mode for Processing extends the Processing Development Environment with the Python programming language.
🌐
Data Science Discovery
discovery.cs.illinois.edu › guides › Python-Fundamentals › brackets
Parentheses, Square Brackets and Curly Braces in Python - Data Science Discovery
March 22, 2024 - Brief description on when to use parentheses `()`, square brackets `[]` and curly braces `{}` in python
🌐
ScienceDirect
sciencedirect.com › topics › engineering › curly-bracket
Curly Bracket - an overview | ScienceDirect Topics
A dictionary is like a list in many ways, but you access it with the name of the item. In technical terms, a dictionary is a set of key:value pairs. The key is the analog to the index of a list, and is, in effect, the name of the item. You define a dictionary using curly braces.
🌐
Quora
quora.com › What-is-the-purpose-of-curly-brackets-in-Python-programming-Are-there-alternative-methods-to-achieve-the-same-result
What is the purpose of curly brackets in Python programming? Are there alternative methods to achieve the same result? - Quora
Answer (1 of 3): The purpose of curly braces in Python is to create a dictionary of key:value pairs. Ex: my_dict = {} The above is an empty dictionary. An example of a dictionary with values is below.
🌐
pythontutorials
pythontutorials.net › blog › is-it-true-that-i-can-t-use-curly-braces-in-python
Is It True? Python Doesn’t Use Curly Braces for Code Blocks (Indentation Explained)
If you’ve dabbled in programming, you’ve likely encountered curly braces {}. Languages like Java, JavaScript, C++, and C# rely on these symbols to define code blocks—groups of statements that belong together (e.g., inside a loop, conditional, or function). But if you’ve tried Python, you might have noticed something missing: those curly braces are nowhere to be found.