header

Objective category: Python's dict data type

Python.Dictionaries (PY.DICT.*)

Contents

iDictionary resources
iData structure review exercises

Objective group FOUND: Foundation concepts: data structures in python

Objective group Objective ID Objective text
FOUND: Foundation concepts PY.DICT.FOUND.1 Create and manipulate small quantities of data in tuples, lists, and dictionaries
PY.DICT.FOUND.2 Process Strings with slicing and built-in methods on String objects

The Python types that we'll review at the start of Python 2:

  1. Numbers
  2. Strings
  3. Lists
  4. Tuples
  5. Dictionaries

Objective group RW: Reading and writing

Objective group Objective ID Objective text
RW: Reading and writing PY.DICT.RW.1 Create, write to, and read from a single dictionary data types in: standalone statements, conditionals, and looping structures
PY.DICT.RW.2 Design and implement nested dictionary structures such that a dictionary oject is stored in the value associated with one or more keys in a parent dictionary object. Demonstrate reading, writing, and updating values in double and multi-leveled nesting dictionaries.

resources

The python foundation maintains the most comprehensive and authoritative documentation on all built-in aspects of the python language. Start here:

listBuilt-in types opening activity

The challenge specification:

  1. Design a dictionary whose keys describe what values you'd like to learn about your peers in this class. Design the dictionary on paper, specifying the data type of the value. You must store at least one of each of our review types.
  2. Once the specification is done, pass the dictionary design to a peer, and ask them to populate the dictionary values with appropriate syntax.
  3. Now, at a computer, create a simple program which creates this dictionary, whose keys are all strings, and hard-code the values from yet a third person's dictionary.
  4. Create a simple mechanism for retrieving the value of one of the keys in the dictionary using user input.
  5. Prepare to demonstrate your program to your peers.

listString slicing exercise

  1. Write a short program that reads in a String and prints out the first two followed by the last two letters of this string only. Before performing this operation, check to make sure the user entered a String of at least 4 letters. If it's too short, reject the input and end the program.
  2. Write a program that checks to see if the second and second-to-last letter of an inputted string are the same letter. If so, print a corresponding message to the user. If not, terminate with an ominous message.
  3. Ask the user for three strings. Input these into three different String variables. Once you have the data, print out these three strings on one line, organized from the shortest to the longest words. If words are the same length, the order is irrelevant.

listLooping review exercise

This exercise is intended to provide a review of basic looping and listing facilities in Python. If this exercise is a challenge, that's okay--it's a check-in exercise!

Specification:

  1. Envision on paper using pseudocode a program which asks the user for an integer. The program then should display the a list that counts from 0 up to this given integer. Finally, the program should display the total of each of the elements of this list added together.
  2. Code the program in Python and test it
  3. Study the sample output for help

Sample program interaction

python output

sendProducts

cakeExtension exercises

Revisit with gusto the differences between the various python Built-in types.

arrow_upward back


Page created in 2019 by Eric Xander Darsow. Original content can be freely reproduced without any permission or attribution according to the site's content use agreement. Any content accessed by links to external sites or content with specific rights notices is governed by its respective use agreements.