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 8409459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:55:00+00:00 2026-06-09T23:55:00+00:00

All – I have a very basic question today … but it has been

  • 0

All –

I have a very basic question today … but it has been preventing me from moving on productively in my programming, so I am posting it here.

I want to create a dictionary that takes a dictionary as a key. Presumably I can only pass a reference to the dictionary as key … only I don’t know how to do that in Python. Here is a toy reduction of what I am trying to do:

def test( dict ):
    a={}
    b={1:1}
    a[ dict ] = b
    return a

a = {0:0}
print test( a ) 

I would like b to be a dictionary of the form { {0:0} : {1:1} }.

Any help with this is much appreciated.

Kind regards –

Pat

  • 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. Editorial Team
    Editorial Team
    2026-06-09T23:55:01+00:00Added an answer on June 9, 2026 at 11:55 pm

    Keys for dictionaries must be hashable items; unfortunately, dictionaries themselves are not hashable (they are mutable, which disqualifies them from being hashable).

    Use their item list, converted to a sorted tuple, instead:

    a[tuple(sorted(dct.items()))] = b
    

    Mutable objects are not hashable because they can be changed in-place, making later key-lookups fail. What would the expected outcome be if you added or removed items from the dictionary you used as the key, for example?

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

Sidebar

Related Questions

all. This question probably has a devilishly simple answer but it has kept me
All of a sudden, Facebook sharing has stopped working on my site. It's been
All, I have the following code: $fetch = mysql_query(SELECT * FROM calendar_events where event_status='booked'
all! A question to all the users of Mac OS X who have used
All, If I run a query like the following: $qry = Select wrong_column from
All -- I have these two methods in one of my classes: public static
All, How can I bind the array of drop down list items returned from
all. We're trying to get some intersect collisions working, but the problem experience is
All, Apologies in advance - this question might be too open-ended for SO. Anyway...
All the guys probably will recommend that I read the follow previously question in

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.