Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Week 5 Class 1

Student Worksheet
I. Before you read

A. Keywords
Look at the Word Cloud of the most frequent words in the text
you are going to read.

1. Which words you do not know? Write down the unknown words and
look them up in a dictionary.

Unknown words:
A. Predicting

2. After checking the vocabulary, write a sentence predicting the topic


that you are going to read in this text.

3. Vocabulary. Read the following words and match them with the
correct meaning.

1. Tuple A. a series or group of symbols, words, or bits


treated as a unit.
2. Key B. an ordered arrangement of material, as in a
library.
3. Strings C. one of a set of marked parts, designated areas,
or levers pressed in operating a typewriter,
computer terminal, calculator, etc.
4. Index D. row of values in a relational database
II. While you read

A. Scanning

1. Scan the text and answer the following questions.

1. What does a pair of braces {} create?


_____________________________________________________________

2. How can you check if a single key is in the dictionary?


_____________________________________________________________

B. Skimming

2. Skim the text and match the sentence in the correct order.

1. Dictionaries are sometimes


found in other languages A. dictionaries are indexed by keys

2.Unlike sequences, which are B. since lists can be modified in


indexed by a range of numbers, place using index assignments

3. Tuples can be used as keys C. as “associative memories”

4. You can’t use lists as keys, D. if they contain only strings,


numbers, or tuples
Dictionaries
Another useful data type built into Python is the dictionary (see Mapping Types —
dict). Dictionaries are sometimes found in other languages as “associative
memories” or “associative arrays”. Unlike sequences, which are indexed by a
range of numbers, dictionaries are indexed by keys, which can be any immutable
type; strings and numbers can always be keys. Tuples can be used as keys if they
contain only strings, numbers, or tuples; if a tuple contains any mutable object
either directly or indirectly, it cannot be used as a key. You can’t use lists as keys,
since lists can be modified in place using index assignments, slice assignments,
or methods like append() and extend().

It is best to think of a dictionary as a set of key: value pairs, with the requirement


that the keys are unique (within one dictionary). A pair of braces creates an empty
dictionary: {}. Placing a comma-separated list of key:value pairs within the braces
adds initial key:value pairs to the dictionary; this is also the way dictionaries are
written on output.

The main operations on a dictionary are storing a value with some key and
extracting the value given the key. It is also possible to delete a key:value pair
with del. If you store using a key that is already in use, the old value associated
with that key is forgotten. It is an error to extract a value using a non-existent key.

Performing list(d) on a dictionary returns a list of all the keys used in the


dictionary, in insertion order (if you want it sorted, just use sorted(d) instead). To
check whether a single key is in the dictionary, use the in keyword.

Here is a small example using a dictionary:

>>>
>>> tel = {'jack': 4098, 'sape': 4139}
>>> tel['guido'] = 4127
>>> tel
{'jack': 4098, 'sape': 4139, 'guido': 4127}
>>> tel['jack']
4098
>>> del tel['sape']
>>> tel['irv'] = 4127
>>> tel
{'jack': 4098, 'guido': 4127, 'irv': 4127}
>>> list(tel)
['jack', 'guido', 'irv']
>>> sorted(tel)
['guido', 'irv', 'jack']
>>> 'guido' in tel
True
>>> 'jack' not in tel
False

The dict() constructor builds dictionaries directly from sequences of key-value


pairs:

>>>
>>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])
{'sape': 4139, 'guido': 4127, 'jack': 4098}

In addition, dict comprehensions can be used to create dictionaries from arbitrary


key and value expressions:

>>>
>>> {x: x**2 for x in (2, 4, 6)}
{2: 4, 4: 16, 6: 36}

When the keys are simple strings, it is sometimes easier to specify pairs using
keyword arguments:

>>>
>>> dict(sape=4139, guido=4127, jack=4098)
{'sape': 4139, 'guido': 4127, 'jack': 4098}
III. After you read
Vocabulary

1. The Word Cloud below shows the most frequent words in the text about
Python. Find them and highlight them in the text.

2. Are these words adjectives/nouns/verbs? Classify them and write them in


the correct column.

Adjective Noun Verb

5
2. Look up the unknown words from the Word Cloud.

https://www.wordreference.com/

Understanding my process
1. Think about a recommendation to read Python of texts and share this idea
with your classmates.

2. Read the following statements and mark Yes or No taking into account
your learning process:

Statements Yes No
1. I can use strategies to understand the unknown
words
2 I can scan a text to find specific information

3. I can use skimming to get the general idea of


the text

4. I can use the dictionary correctly to understand


the meaning and parts of speech
Answer Key
I. Before you read

3. Vocabulary. Read the following words and match them with the
correct meaning.

1. Tuple D A. a series or group of symbols, words, or bits treated as a unit.


2. Key C B. an ordered arrangement of material, as in a library.
3. Strings A C. one of a set of marked parts, designated areas, or levers
pressed in operating a typewriter, computer terminal,
calculator, etc.
4. Index B D. row of values in a relational database

II. While you read

1. Scan the text and answer the following questions.

1. What does a pair of braces {} create?

A pair of braces creates an empty dictionary: {}

2. How can you check if a single key is in the dictionary?

To check whether a single key is in the dictionary, use the in keyword.

Skimming

1. Skim the text and match the sentence in the correct order.

1.Dictionaries are sometimes C a. dictionaries are indexed


found in other languages by keys
2.Unlike sequences, which are A b. since lists can be modified in
indexed by a range of numbers, place using index assignments
3. Tuples can be used as keys D c. as “associative memories”
4. You can’t use lists as keys, B d. if they contain only strings,
numbers, or tuples

III. After you read


2. Are these words adjectives/nouns/verbs? Classify them and write them in
the correct column.

Adjective Adverb Verb

1 single Instead, want, use

2 small here perform, index

3 old already sort, check

4 associative just associate, forget

5 Key also index

You might also like