Suppose I have loaded this into a list:
info = ['apple: 1', 'orange: 2', 'grape: 3']
How can I turn that into something like
info = {line[0]: line[1] for line.split(': ') in info}
So that I actually have a dict?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re very close!
You could do it the way you tried to in Python 2.7+, but you’d have to split the lines separately, so using
dictis better.Here’s what I mean: