Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 154689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:01:24+00:00 2026-05-11T10:01:24+00:00

So let’s say I wanna make a dictionary. We’ll call it d . But

  • 0

So let’s say I wanna make a dictionary. We’ll call it d. But there are multiple ways to initialize a dictionary in Python! For example, I could do this:

d = {'hash': 'bang', 'slash': 'dot'} 

Or I could do this:

d = dict(hash='bang', slash='dot') 

Or this, curiously:

d = dict({'hash': 'bang', 'slash': 'dot'}) 

Or this:

d = dict([['hash', 'bang'], ['slash', 'dot']]) 

And a whole other multitude of ways with the dict() function. So obviously one of the things dict() provides is flexibility in syntax and initialization. But that’s not what I’m asking about.

Say I were to make d just an empty dictionary. What goes on behind the scenes of the Python interpreter when I do d = {} versus d = dict()? Is it simply two ways to do the same thing? Does using {} have the additional call of dict()? Does one have (even negligible) more overhead than the other? While the question is really completely unimportant, it’s a curiosity I would love to have answered.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:01:25+00:00Added an answer on May 11, 2026 at 10:01 am
    >>> def f(): ...     return {'a' : 1, 'b' : 2} ...  >>> def g(): ...     return dict(a=1, b=2) ...  >>> g() {'a': 1, 'b': 2} >>> f() {'a': 1, 'b': 2} >>> import dis >>> dis.dis(f)   2           0 BUILD_MAP                0               3 DUP_TOP                            4 LOAD_CONST               1 ('a')               7 LOAD_CONST               2 (1)              10 ROT_THREE                         11 STORE_SUBSCR                      12 DUP_TOP                           13 LOAD_CONST               3 ('b')              16 LOAD_CONST               4 (2)              19 ROT_THREE                         20 STORE_SUBSCR                      21 RETURN_VALUE         >>> dis.dis(g)   2           0 LOAD_GLOBAL              0 (dict)               3 LOAD_CONST               1 ('a')               6 LOAD_CONST               2 (1)               9 LOAD_CONST               3 ('b')              12 LOAD_CONST               4 (2)              15 CALL_FUNCTION          512              18 RETURN_VALUE         

    dict() is apparently some C built-in. A really smart or dedicated person (not me) could look at the interpreter source and tell you more. I just wanted to show off dis.dis. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let me explain best with an example. Say you have node class that can
Let me try to explain by example. Say website is hosted at example.com (NOT
Let's say I have thousands of users and I want to make the passwords
Let's say I can call a method like this: core::get() . What is the
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say there is a graph and some set of functions like: create-node ::
Let's say I have multiple requirements for a password. The first is that the
Let say I've this URL: http://example.com/image-title/987654/ I want to insert download to the part
Let's say I got a Map<String, String> and I wanna remove all the entries

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.