Python Dictionary

SiHodgy007
SiHodgy007 used Ask the Experts™
on
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"))
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014

Commented:
variable = {"Happy": "Happy Gilmore","Silly":"Silly Monkey","Funny":"Funny Donkey"}
print(variable.get("Happy"))

Open in new window

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
Solved
list = list.split()
dict = {k:v for k,v in (x.split(':') for x in list) }
Solved myself

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial