#๐ is there a cute way to preload a dictionary with keys and a default value?
17 messages ยท Page 1 of 1 (latest)
@mint notch
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
@sullen perch :x: Your 3.12 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "/home/main.py", line 1, in <module>
003 | my_dict = dict.fromkeys(*'abc', None)
004 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
005 | TypeError: fromkeys expected at most 2 arguments, got 4
@cosmic topaz :white_check_mark: Your 3.12 eval job has completed with return code 0.
{'a': None, 'b': None, 'c': None}
mb
List comp is better for mutable values like empty list
or even consider defaultdict
bet
this was mostly just bothering me as a thing i thought u could do but couldn't remember how
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.