I'm trying to update some code from python 2 notation to python 3 notation. The code inserts into a string from a dictionary. In python 2, this looks like:
string = "Today I saw a %(animal)s at the park."
ex_dict = {"animal": "dog"}
mod_string = string % ex_dict
print mod_string
which would result in
Today I saw a dog at the park.
I tried the updated notation using the .format
insertion:
string = "Today I saw a {} at the park."
mod_string = string.format(ex_dict)
print(mod_string)
which gives the unwanted result:
Today I saw a {'animal': 'dog'} at the park.
What is the proper way to replace the %s %
notation with the {}.format()
notation in this case?