0

I was attempting to make an empty dictionary and use set default to allow duplicates. For some reason, the only variable name that would work is “d1”. Is there a reason why? I had another friend with way more experience in Python programming tell me to change it to d1, but I don’t know why.

I tried newdict and even d2 as a placeholder name. Neither would show as variables even after being assigned to an empty dictionary.

9
  • 4
    You can use any name you want for your variables. Please show your code that's not working, along with the full traceback of the error. Commented Feb 10, 2023 at 18:09
  • 3
    Can you add your code where you are initializing the dictionaries? Commented Feb 10, 2023 at 18:10
  • 3
    Have you tried asking your friend? Commented Feb 10, 2023 at 18:13
  • I did ask my friend, but he didn’t really offer an explanation! I’m new to coding so maybe it was common sense for him? Commented Feb 10, 2023 at 18:28
  • I don’t have current access to my code, but I was combining a list of keys and values (some keys assigned to multiple values) using set default code. I kept an empty list for my new dictionary d1 = {} and later did d1.setdefault Commented Feb 10, 2023 at 18:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.