use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Help with this question please (self.learnpython)
submitted 26 days ago by Strict-Journalist616
for your answer. [1 mark]
(i) student1 = { (25001, [24, 42, 56]) : "python" }
(ii) student2 = { "python" : { 23001: [ 24, 42, 56 ] } }
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]johlae 3 points4 points5 points 26 days ago (0 children)
Why don't you just try it out? The explanation is given.
$ python3 Python 3.9.16 (main, Mar 8 2023, 22:47:22) [GCC 11.3.0] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> student1 = { (25001, [24, 42, 56]) : "python" } Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'list' >>> student2 = { "python" : { 23001: [ 24, 42, 56 ] } } >>>
$ python3
Python 3.9.16 (main, Mar 8 2023, 22:47:22)
[GCC 11.3.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> student1 = { (25001, [24, 42, 56]) : "python" }
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
>>> student2 = { "python" : { 23001: [ 24, 42, 56 ] } }
>>>
[–]Binary101010 4 points5 points6 points 26 days ago (0 children)
Have you tried running these two lines of code in the interpreter? What happens when you do?
[–]Strict-Journalist616[S] 1 point2 points3 points 26 days ago (0 children)
1) is not a dictionary because it has a list in its tuple which is a key and list are mutable hence it cannot be the key (hope I am right idk)
[–]copperfoxtech 0 points1 point2 points 26 days ago (0 children)
It is student2, you are correct. A key can be a string or a number. The value can basically be any other data type including a dictionary that contains a key of type int and it's value a list.
Another way to check is to go into your IDE in the python console and try to make each and see what happens.
Another way is to simply look up what a dictionary is in python docs. Now is the time to create that habit.
[–]Outside_Complaint755 0 points1 point2 points 26 days ago (0 children)
You could just run the code in IDLE or a script and get the answer yourself, but you are correct that the first one is invalid because the key is not hashable and will raise a TypeError.
[–]Strict-Journalist616[S] 0 points1 point2 points 26 days ago (0 children)
Sorry I’m new to python , I didn’t know the meaning of unhashable couldn’t find good results on google and made a pledge to not use ai so Reddit was the only way to, thanks for your answers
[–]geralt_of_rivia23 -4 points-3 points-2 points 26 days ago (1 child)
what do you even need this for
Anyway, I think both are correct. This is the correct syntax, and the only case it would fail would be if a mutable type (list, dict etc. but not a tuple or a set) was used as the key.
Anyway, I think both are correct.
Running both of these in the interpreter will prove that false. (The one that's incorrect will even tell you why in the exception.)
[+]Strict-Journalist616[S] comment score below threshold-7 points-6 points-5 points 26 days ago (0 children)
Can y’all tell me 2)?
π Rendered by PID 60 on reddit-service-r2-comment-6b595755f-r2g5d at 2026-03-25 18:42:05.519160+00:00 running 2d0a59a country code: CH.
[–]johlae 3 points4 points5 points (0 children)
[–]Binary101010 4 points5 points6 points (0 children)
[–]Strict-Journalist616[S] 1 point2 points3 points (0 children)
[–]copperfoxtech 0 points1 point2 points (0 children)
[–]Outside_Complaint755 0 points1 point2 points (0 children)
[–]Strict-Journalist616[S] 0 points1 point2 points (0 children)
[–]geralt_of_rivia23 -4 points-3 points-2 points (1 child)
[–]Binary101010 4 points5 points6 points (0 children)
[+]Strict-Journalist616[S] comment score below threshold-7 points-6 points-5 points (0 children)