Python 2.7: Print a dictionary without brackets and quotation marks
dictionary, printing, python, python-2.7
Solution
Using the `items` dictionary method:
print('\n'.join("{}: {}".format(k, v) for k, v in myDict.items()))
Output:
Restaurant: Place
Codeacademy: Place to learn
Harambe: Gorilla
Expanded:
for key, value in myDict.items():
print("{}: {}".format(key, value))
Problem
``` myDict = {"Harambe" : "Gorilla", "Restaurant" : "Place", "Codeacademy" : "Place to learn"} ``` So, I want to print out a dictionary. But I want to do it like it looks like an actual list of things. I can't just do `print myDict`, as it will leave all the ugly stuff in. I want the output to look like `Harambe : Gorilla, Restaurant : Place, etc` So what do I do? I haven't found a post meeting what I want. Thanks in advance.