Python Dictionary

I have a variable which outputs

Happy Gilmore
Silly Monkey
Funny Donkey

I would look like to load these into a dictionary so I can use

print(variable.get("Happy"))
LVL 2
SiHodgy007Asked:
Who is Participating?
 
SiHodgy007Connect With a Mentor Author Commented:
Solved
list = list.split()
dict = {k:v for k,v in (x.split(':') for x in list) }
0
 
aikimarkCommented:
variable = {"Happy": "Happy Gilmore","Silly":"Silly Monkey","Funny":"Funny Donkey"}
print(variable.get("Happy"))

Open in new window

0
 
SiHodgy007Author Commented:
Sorry the Variable outputs the above, how do I manipulate it into a dictionary. You have just re-wrote the variable.

Get Happy should return Gilmore
0
 
SiHodgy007Author Commented:
Solved myself
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.