Organising information: unordered structures

Communication 1

No communications!

Actually, this is not entirely true...

It is partial examination time!

Any question about the previous lecture?

Historic hero: Jorge Luis Borges

He was an Argentine short-story writer, poet, and essayist

He produced several works laying between philosophical literature and fantasy genre

Main topics of his works: dreams, labyrinths, libraries, mirrors, the notion of infinity, and religions

The Library of Babel

Big library, made of hexagonal rooms

  • 20 bookshelves in four of the walls of each room (5 bookshelves per wall)

  • Each bookshelf contains 35 books

  • Each book counts 410 pages

  • Each page organised in 40 lines

  • Each line contains 80 characters

The library contains all the books that have been and will be written by using every possible combination of 25 basic characters: 22 letters, the period, the comma, and the space

Does infinity exist?

Opening sentence: [the Library] is composed of an indefinite and perhaps infinite number of hexagonal galleries

The narrator suggests that the library is made of an infinite number of books, contained in an infinite number of rooms – however, is really this the case?

Mathematical infinity exists, it is an abstract concept: the set of all the prime numbers, which is an infinitive set

Often we refer to an infinite amount of something when actually we are speaking about a quite extensive and huge mass of stuff

What about the Library?

It contains only 2*101834097 of books

That number has been obtained by considering all the possible combination of all the finite set of charaters in all the 410 pages in all the books that can be generated

In existing computational systems (e.g. an electronic computer), we must be aware that infinity (e.g. the tape of a Turing Machine) is an illusion

Prelimilaries: classes

Class: extensible template for creating objects having a certain type (e.g. the class for strings, for integers, for lists)

Object: a value of a certain kind (e.g. "a string", 42, list([1,2,3]))

Method: a function that can be run only if directly called via an object (e.g. <list>.append(<item>))

Set: example

Set: definition

A set is a countable sequence of unordered and non-repeatable elements

Countable: it is possible to know the length of the set (i.e. how many elements it contains) – in Python, we can use the function len(<countable_object>)

Unordered: the elements are placed in the set without any particular order

Unrepeatable: the elements cannot appear more than one time in the set

Set: methods

Create a new set: set()

Add new element: <set>.add(<element>)

Remove element: <set>.remove(<element>)

Add elements from another set: <set>.update(<another_set>)

Use methods on set

my_first_set = set()
my_first_set.add(34)
my_first_set.add(15)
my_first_set.add("Silvio")
my_first_set.remove(34)
my_first_set.update(my_first_set)

my_first_set = 34 15 "Silvio"

Dictionary: example

Dictionary: definition

A dictionary is a countable collection of unordered key-value pairs, where the key is non-repeatable in the dictionary

Unrepeatability of keys: the same key cannot be included twice in the dictionary

Dictionary: methods

Create a new dictionary: dict()

Add new pair: <dictionary>[<key>] = <value>

Remove a pair: del <dictionary>[<key>]

Get value by key: <dictionary>.get(<key>)

Add pairs from another dictionary: <dictionary>.update(<another_dictionary>)

Use methods on dictionary

my_first_dict = dict()
my_first_dict["age"] = 34
my_first_dict["day of birth"] = 15
my_first_dict["name"] = "Silvio"
del my_first_dict["age"]
my_first_dict.update(my_first_dict)
my_first_dict.get("name")

my_first_dict =

"name": "Silvio"
"day of birth": 15
"age": 34

END Organising information: unordered structures