Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Concise idiom to initialize dictionaries
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Bengt Richter, post: 1789004"] Others explained why locals()[x] worked interactively, and not in a function, but if you just want a one-liner, you could just unpack a listcomp: ({}, {}, {}) If you have single-letter names, you can avoid the count by stepping through the letters: ({}, {}, {}) Or if you have a long target list and you can just type it and copy/paste it like: [9440400, 9440976, 9438816, 9441120, 9440256, 9440544] The dicts are separate, as you can see: ({0: '0'}, {1: '1'}, {2: '2'}) Regards, Bengt Richter [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Concise idiom to initialize dictionaries
Top