Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Counting with dictionaries
Grouping with dictionaries
Linking with dictionaries
16. Summary


Good job! It's time to wrap things up. Before we do this section's quiz, let's have a quick review of what we've covered:

  1. To iterate over dictionary keys, use either:
    for k in dictionary:


    for k in dictionary.keys():
  2. To iterate over dictionary values, use:
    for v in dictionary.values():
  3. To get both values and keys during dictionary iteration, use:
    for k, v in dictionary.items():
  4. Dictionaries are often used to count elements:
    votes = [...]
    dict_results = {}
    for vote in votes:
      if vote not in dict_results:
        dict_results[vote] = 0
      dict_results[vote] += 1
  5. The syntax above can be simplified to:
    votes = [...]
    dict_results = {}
    for vote in votes:
      dict_results[vote] += dict_results.get(vote, 0) + 1
  6. Dictionaries are also used to group elements by a given characteristic, for instance:
    names = [...]
    groups_dict = {}
    for name in names:
      key = len(name)
      if key not in groups_dict:
        groups_dict[key] = []
  7. You can update the values in a dictionary based on another dictionary using:
  8. Great! Are you ready for the quiz?


Click Next exercise to continue.