Dictionaries - CS111
Dictionaries
CS111 Computer Programming
Department of Computer Science Wellesley College
Looking up English words in the dictionary
Concepts in this slide: Comparing sequences to collections.
Sequence : a group of things that come one after the other
Collection : a group of (interesting) things brought together for some purpose
Is a sequence a collection?
Is a collection a sequence?
Dictionaries 2
Looking up English words in the dictionary
Concepts in this slide: Comparing sequences to collections.
Sequence : a group of things that come one after the other
Collection : a group of (interesting) things brought together for some purpose
Is a sequence a collection? Yes!
Is a collection a sequence? No.
? A sequence is an ordered collection in which elements can be accessed by index. All sequences are collections but not all collections are sequences.
Dictionaries 3
Properties of sequences and collections
Concepts in this slide: Properties that are common and distinct for the two categories.
? Collections
? Find their length with len ? Check an element membership in the collection with in ? Are iterables (one can iterate over their elements with a loop)
? Sequences
? Use indices to access elements, e.g. myList[2] ? Use slice operations to access subsequences, e.g. myList[2:5]
? Mutable: can be changed through object methods. ? Immutable: cannot be changed.
Dictionaries 4
Python collections
Concepts in this slide: Definitions and examples of Python collection types.
Type list tuple string
Description a mutable sequence of arbitrary objects
an immutable sequence of arbitrary objects an immutable sequence of characters
Example [-100, "blue", (1, 10), True] (2017, "Mar", 2)
"Go Wellesley!"
range an immutable sequence of numbers
range(3)
set
a mutable unordered collection of distinct {1, 4, 5, 23}
objects.
dict
a mutable unordered collection of
{"orange": "fruit",
key:value pairs, where keys are
3: "March",
immutable and values are any Python
"even": [2,4,6,8]}
objects
Dictionaries 5
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- lecture 14 nested lists tuples and dictionaries
- topic 6 lists sets tuples dictionaries
- data structures in python grapenthin
- map list stack queue set university of washington
- writing python 2 3 compatible code
- how to get keys of python dictionary as list
- python 3 beginner s reference cheat sheet http www
- create a list of keys values key value tuples from a
- dictionaries
- dictionaries cs111
Related searches
- student dictionaries for elementary students
- list of dictionaries in python
- python list of dictionaries append
- creating a list of dictionaries in python
- a list of dictionaries python
- create list of dictionaries python
- sort list of dictionaries python
- python sort list of dictionaries by value
- array of dictionaries python
- how to add dictionaries python
- slang dictionaries online
- dictionaries in spanish