Your problem is that you need to use square brackets([]
) instead of parenthesis(()
). Like so:
for email in contact_emails: print('%s is %s' % (contact_emails[email], email)) # notice the []'s
But I recommend using the .items()
( that would be .iteritems()
if your using Python 2.x) attribute of dict
s instead:
for name, email in contact_emails.items(): # .iteritems() for Python 2.x print('%s is %s' % (email, name))
Thanks to @PierceDarragh for mentioning that using .format()
would be a better option for your string formatting. eg.
print('{} is {}'.format(email, name))
Or, as @ShadowRanger has also mentioned that taking advantage of prints variable number arguments, and formatting, would also be a good idea:
print(email, 'is', name)
Related Posts:
- Iterating over dictionaries using ‘for’ loops
- How do I sort a dictionary by value?
- How do I sort a dictionary by value?
- How do I sort a dictionary by value?
- Check if a given key already exists in a dictionary
- How does collections.defaultdict work?
- Is a Python dictionary an example of a hash table?
- Converting dictionary to JSON
- How do I merge two dictionaries in a single expression (taking union of dictionaries)?
- Python list of dictionaries search
- Updating a dictionary in python
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- unhashable type: ‘dict’ Type Error [duplicate]
- How to copy a dictionary and only edit the copy
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- How can I remove a key from a Python dictionary?
- How to solve dictionary changed size during iteration error?
- DataFrame constructor not properly called
- TypeError: ‘type’ object is not subscriptable when indexing in to a dictionary
- TypeError: ‘dict’ object is not callable
- Getting key with maximum value in dictionary?
- Error: ” ‘dict’ object has no attribute ‘iteritems’ “
- Getting key with maximum value in dictionary?
- Error: ” ‘dict’ object has no attribute ‘iteritems’ “
- How can I get dictionary key as variable directly in Python (not by searching from value)?
- Are dictionaries ordered in Python 3.6+?
- How can I remove a key from a Python dictionary?
- append multiple values for one key in a dictionary [duplicate]
- Convert a python dict to a string and back
- Delete an element from a dictionary
- How to add multiple values per key in python dictionary
- Get key by value in dictionary
- How to add multiple values to a dictionary key in python?
- Determine the type of an object?
- enumerate() for dictionary in python
- Reverse / invert a dictionary mapping
- Creating 2D dictionary in Python
- How to print a dictionary’s key?
- Converting Dictionary to List?
- How to pretty print nested dictionaries?
- Convert a Pandas DataFrame to a dictionary
- How to index into a dictionary?
- In Python, when to use a Dictionary, List or Set?
- Add a new item to a dictionary in Python
- How can I add new keys to a dictionary?
- How can I get list of values from dict?
- TypeError: string indices must be integers, not str // working with dict
- How do I format a string using a dictionary in python-3.x?
- Creating a dictionary from a csv file?
- Map to List error: Series object not callable
- How to return dictionary keys as a list in Python?
- How can I create an array/list of dictionaries in python?
- Comparing two dictionaries and checking how many (key, value) pairs are equal
- How to save a dictionary to a file?
- Mapping over values in a python dictionary
- TypeError: ‘dict_keys’ object does not support indexing
- How to convert an XML string to a dictionary?
- How do I print the key-value pairs of a dictionary in python
- How do I print the key-value pairs of a dictionary in python
- How do I make a dictionary with multiple keys to one value?
- Python: How to check if keys exists and retrieve value from Dictionary in descending priority
- Appending values to dictionary in Python
- Python dictionary from an object’s fields
- Writing a dictionary to a csv file with one line for every ‘key: value’
- How to convert a file into a dictionary?
- Append a dictionary to a dictionary
- Python Add to dictionary loop
- AttributeError: ‘str’ object has no attribute ‘items’
- JSON object must be str, bytes or bytearray, not dict
- convert csv file to list of dictionaries
- Declaring a multi dimensional dictionary in python
- how to concatenate two dictionaries to create a new one in Python?
- python-How to solve KeyError: 2?
- How to search through dictionaries?
- Change the name of a key in dictionary
- What is an easy way to implement fprintf in python?
- How can I extract all values from a dictionary in Python?
- Create a list with initial capacity in Python
- Accessing dict_keys element by index in Python3
- Iterating over dictionary items(), values(), keys() in Python 3
- Flatten nested dictionaries, compressing keys
- python dictionary error AttributeError: ‘list’ object has no attribute ‘keys’
- Convert list of dictionaries to a pandas DataFrame
- Purpose of “%matplotlib inline”
- Can’t fix “zipimport.ZipImportError: can’t decompress data; zlib not available” when I type in “python3.6 get-pip.py”
- Arrays used as indices must be of integer (or boolean) type
- How to determine a Python variable’s type?
- How to convert IPython notebooks to PDF and HTML?
- ‘Jupyter’ is not recognized as an internal or external command
- How to print spaces in Python?
- installing urllib in Python3.6
- What is sys.maxint in Python 3?
- How can I install the latest Anaconda with wget
- sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 74 supplied
- Python 101: Can’t open file: No such file or directory
- super() fails with error: TypeError “argument 1 must be type, not classobj” when parent does not inherit from object
- Python cant convert ‘list’ object to str error [closed]
- Failed building wheel for Twisted in Windows 10 python 3
- Package libffi was not found in the pkg-config search path REDHAT6.5
- Line is too long. Django PEP8