
Up to this point, we’ve been working with what are called “primitive” data types in Python. These include integer, float, string, and Boolean.
But we can imagine scenarios where we want to be able to work with more complex data structures or more complex ways of storing and accessing information in a programming language.
In this chapter, we’re going to focus on some of the one-dimensional (or linear) data structures available to us in Python. These include strings, lists, tuples, sets, and dictionaries.
| Name | Syntax | Example | Description |
|---|---|---|---|
| String | str(), "" | "Hello world!" | Sequence of characters |
| List | list(), [] | ["apple", "banana", "pear"], [1, 3, 5, 7] | Sequence of objects/values |
| Dictionary | dict(), {} | {'first_name': 'Knute', 'last_name':'Rockne', 'class':'1918'} | Key-value pairs |
| Set | set(), {} | {"apple", "banana", "pear"}, {1, 3, 5, 7} | Unordered group of unique values |
| Tuple | tuple(), () | ("apple", "banana", "pear"), (1, 3, 5, 7) | Ordered group of values that can include duplicates |
We can use a few key questions or attributes to distinguish or compare these data structures:
Mutability: Can values in the structure be changed once it has been created or assigned to a variable?
Order: Does the order of values in the structure have meaning/significance, or is order not significant?
Indexing/Slicing: Can values in the structure be accessed using their position or index? Can we isolate values in the structure using their position?
Duplicates: Does the structure allow duplicate values?
This chapter provides an overview of foundational programming concepts in the areas of data structures and data storage, with a focus on Python syntax.
Topics covered include:
Linear and associative arrays
Indexing
String objects and methods
Lists and list methods
Dictionaries
Tuples
Sets
Acknowledgements¶
Elements of this chapter were adapted from materials developed by:
Dr. Peter Bui for the CSE 10101 “Elements of Computing I” course.
Dr. Janet Davis for the the CSC 105 “The Digital Age” course.
Dr. Corey Pennycuff for the CSE 10101 Elements of Computing (Fall 2019).
Dr. Lindsay K. Mattock for the the SLIS 5020 Computing Foundations course.
Application¶
Your answers to this chapter’s application questions should be added to the notebook template.
Google Colab link (ND users only)
Submit the Colab link on Canvas for the assignment submission.