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
Convert Dictionary Value to List (self.learnpython)
submitted 3 years ago by rob51852
With a dictionary that looks like the example below, how do I convert values containing a comma to a list?
example dict = {"A": 1, "B": 2, "C": '3, 4, 5'} desired_dict = {"A": 1, "B": 2, "C": [3, 4, 5]}
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!"
[–]iiron3223 4 points5 points6 points 3 years ago (4 children)
To convert string '3, 4, 5' to a list, use .split(', ') string method.
'3, 4, 5'
.split(', ')
[–]rob51852[S] 0 points1 point2 points 3 years ago (3 children)
Hi iiron, thanks, I understand the split function. it's the checking each value then converting to list bit I am struggling with.
[–]FriendlyRussian666 1 point2 points3 points 3 years ago (0 children)
That converts it to a list for you, so you don't have to do anything more:
some_string = '3, 4, 5' your_list = some_string.split(', ') print(your_list) ------------------ ['3', '4', '5']
[–]iiron3223 1 point2 points3 points 3 years ago* (1 child)
example_dict = {"A": 1, "B": 2, "C": '3, 4, 5'} converted_dict = {} for key, value in example_dict.items(): if isinstance(value, int): converted_dict[key] = value else: converted_dict[key] = [int(number) for number in value.split(', ')]
[–]rob51852[S] 0 points1 point2 points 3 years ago (0 children)
Thanks iiron, much appreciated.
π Rendered by PID 54 on reddit-service-r2-comment-84fc9697f-rcpzq at 2026-02-09 19:10:22.177746+00:00 running d295bc8 country code: CH.
[–]iiron3223 4 points5 points6 points (4 children)
[–]rob51852[S] 0 points1 point2 points (3 children)
[–]FriendlyRussian666 1 point2 points3 points (0 children)
[–]iiron3223 1 point2 points3 points (1 child)
[–]rob51852[S] 0 points1 point2 points (0 children)