09-16 - Dictionaries

Lord, we pray for those making international and national decisions about the ‘Information Super-Highway’;
that the whole range of considerations - political, economic, personal, sectional, communal - may be properly taken into account.

Lord, we pray for those setting up and administering national data-banks; we give thanks for the good they can do in co-ordinating information. We remember those who misuse the information they hold.

Lord, we pray for those involved in Research and Development in computers; we remember the power and responsibility they have for making changes in our world and our lives. We remember those who have lost their jobs as a result of new technology.

Lord, we pray for those who have boring keyboard jobs, those who suffer from Repetitive Strain Injury, or eyestrain. We pray for willingness to deal with the causes of such problems.

Lord, we pray for those in small computing businesses; the difficulties they face in chasing creditors; the stress on them, the risks they have to take - perhaps even with their own homes.

Lord, we pray for those who write computer games: some which are used to do much good at school, others to encourage people to gamble, some which are used just to make money. We pray for those who are addicted to computer and arcade games, and for their families; and for those who are anxious about the violence of some computer games.

Lord, we pray for those frightened of computers and other sorts of new technology; those who feel they cannot master using them; those who feel old or who lose their confidence in the face of change and new things.

Lord, we pray that technology may be the servant, not the controller of our lives.

(From ‘Work in Worship’, Peterborough Diocese People and Work Programme)

Retrieval

Consider the following Python code snippet:

data = (1, 2, 3, 4, 5)
data[2] = 99

Explain why this code will result in an error. How would you modify the code to achieve a similar effect with a list instead of a tuple? Provide the modified code and describe the differences between using a list and a tuple for this operation.

What is the difference between a list and a tuple in Python when it comes to their creation and modification?

  • How do you create a list and a tuple with the same values? Provide examples.
  • Can you change the elements of a list after it’s created? Can you do the same with a tuple?

What will be the output of the following Python code?

nested_list = [[1, 2], [3, 4]]
nested_list[0][2] = 5
print(nested_list)

The goal of the following code is to create a new list new_library based on an original library (games_library). However, the code does not work as intended. What is the problem, and how can it be resolved?

games_library = ['Super Mario', 'The Legend of Zelda', 'The Elder Scrolls']
new_library = games_library
new_library.append('Minecraft')

Dictionaries

  • Mapping types: have keys which map to values
  • A pair of key and value is called an entry
  • Dictionaries are NOT ORDERED! But they are subscriptable (with the keys - which have to be immutable objects)
phones = {'Sarah':'476-3321', 'Nathan':'351-7743'} 
users = {'Name':'Molly', 'Age':18}   
emp = {} # an empty dictionary

You can add a new entry by just specifying it:

phones['Bob'] = '123-4567'
print(phones)
{'Sarah': '476-3321', 'Nathan': '351-7743', 'Bob': '123-4567'}

Or also change values using the keys:

phones['Sarah'] = '999-9999'
print(phones)
{'Sarah': '999-9999', 'Nathan': '351-7743', 'Bob': '123-4567'}

To delete, use:

del phones['Nathan']
print(phones)
{'Sarah': '999-9999', 'Bob': '123-4567'}

Dictionary methods

Operation Description
clear() Removes all the elements from the dictionary
copy() Returns a copy of the dictionary
fromkeys() Returns a dictionary with the specified keys and value
get() Returns the value of the specified key
items() Returns a list containing a tuple for each key value pair
keys() Returns a list containing the dictionary’s keys
pop() Removes the element with the specified key
popitem() Removes the last inserted key-value pair
setdefault() Returns the value of the specified key. If the key does not exist: insert the key, with the specified value
update() Updates the dictionary with the specified key-value pairs
values() Returns a list of all the values in the dictionary

Limits of representation

A world of 0’s and 1’s

  • Think about how much we can represent as digital information: numbers, text, images…
    • See, for example, how integers and floats are represented as binary numbers
    • The ASCII table, for example, is used to represent text. And the UNICODE system is used for more character variety.
    • The bitmap format, for example, is also a way to represent an image with many triplets corresponding to red, green and blue color intensities.

“For computers to reason about data at all, they currently must reduce all information to bits. Bits are simply 1’s and 0’s, nothing more: the symbol 1 has no inherent meaning, nor does the symbol 0. The origin of the word”bit” was from the 1948 paper by Claude Shannon, who was trying to find a way to represent the theoretically smallest possible unit of information to solve problems of audio compression in telephones. […] All that was left, from Shannon’s perspective, was “pure” information, with no inherent meaning: two symbols with which to represent phone call audio, and anything else in the universe: 1 and 0, strung together in arbitrarily long sequences to represent anything.” Amy J. Ko, “Encoding Information”

  • How can we explain the success of this digital encoding? Basically, it is the success of digital electronics. Digital information is movable, stable and manipulable.

“How can we act remotely on little-known events, places and people? Answer: bringing home these events, places and people. How can you do this if you are far away? By inventing means that (a) make them movable so that they can be brought, (b) keep them stable so that they can be brought and carried without distortion, decomposition or deterioration, and (c) are combinable in such a way that, whatever the matter of which they are made, can be accumulated, aggregated or shuffled like a deck of cards. […] The history of science [and technology] is largely the history of the mobilization of anything that can be made to move and embark on a journey home, entering the universal census.” - Bruno Latour, Science in Action, p. 348 and 350

  • For humans, it really doesn’t help to code everything as simple 2-symbol sequences (0’s and 1’s) - it becomes illegible. But for automated machines, it is extremely efficient - from the point of view of design, stability and speed.
    • Thus, we need:
      1. Devices to convert reality to digital information - sensors
      2. Devices to let us manipulate this digital information - interfaces (screens, paper, etc)
      3. Devices to convert our digital information back to reality - actuators
  • Thus we are kind of trapped in the interface bottleneck: everything we usually do in the world needs to be done through screens…

Should we really encode everything as information?

  • How much are we losing by encoding things as information? Remeber: data is always a selective portrait of reality (full of biases).

  • Data privacy is a big issue in today’s society, called by sociologist Shoshanna Zuboff as The Age of Surveillance Capitalism. To have data about people and things is is to have power and value.

  • Or, as philosopher Byung-Chul Han puts it, everything today is coerced into visibility and transparency The Transparency Society. “I am seen, therefore I am”.

The secret things belong unto the LORD our God: but those things which are revealed belong unto us and to our children for ever, that we may do all the words of this law. Deuteronomy 29:29

Moderating our curiosity

  • To acknowledge and protect what should be hidden, we need to cultivate a virtuous curiosity.

    • Thomas Aquinas speaks of the difference between studiositas (virtue) and curiositas (vice) (see more in this interesting article). There are at least 7 vices of curiosity:

    ARROGANCE: seeking knowledge of things that no one is supposed to know;

    NOSYNESS: seeking knowledge that may belong to some people, but not to us;

    DISTRACTION: seeking knowledge of things that are not convenient to know at a certain time;

    IMMODERATION: wanting to know something with an unhealthy desire (all forms of curiosity are failures of temperance, but this label helps to isolate this specific aspect);

    IMPERTINENCE: seeking to know things in a more certain way than one can know, doing violence to the object of knowledge;

    SUPERFICIALITY: disrespecting the object of knowledge, being content with a superficial understanding and quickly moving on to something else;

    POSSESSIVENESS: delighting not in the object of knowledge, but in the act of knowing it. It resembles, on an intellectual level, the vice of greed.

Presence versus re-presence

Furthermore, when we deal with digital information, we are only dealing with past - a frozen portrait of something that happened. To live in interfaces is to live in the past.

  • The contrast to this would be to live in the present. To live in the present, we acknowledge presence, and not re-presence (representations).
  • Thus, as Christians seeking the common good, we would really have to think about an equilibrium between past and present, data and current life, virtual and material. Maybe we are living in a world where this can be quite unbalanced…

“Physical reality seems to recede in proportion as man’s symbolic activity advances. Instead of dealing with things themselves, man is, in a sense, constantly talking to himself. He has become so involved in linguistic forms, in artistic images, in mythical symbols or in religious rites that he cannot see or know anything except through the interposition of an artificial medium.” Ernest Cassirer, “An Essay on Man”