<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <h1>Table of Contents<span class="tocSkip"></span></h1>
<div class="toc"><ul class="toc-item"><li><span><a href="#Containers" data-toc-modified-id="Containers-1"><span class="toc-item-num">1&nbsp;&nbsp;</span>Containers</a></span><ul class="toc-item"><li><span><a href="#1.-Tuples" data-toc-modified-id="1.-Tuples-1.1"><span class="toc-item-num">1.1&nbsp;&nbsp;</span>1. Tuples</a></span><ul class="toc-item"><li><span><a href="#1.1-Tuples-are-(as-the-rest-of-elements-of-Python)-objects" data-toc-modified-id="1.1-Tuples-are-(as-the-rest-of-elements-of-Python)-objects-1.1.1"><span class="toc-item-num">1.1.1&nbsp;&nbsp;</span>1.1 Tuples are (as the rest of elements of Python) objects</a></span></li><li><span><a href="#1.2.-Tuple-definition" data-toc-modified-id="1.2.-Tuple-definition-1.1.2"><span class="toc-item-num">1.1.2&nbsp;&nbsp;</span>1.2. Tuple definition</a></span></li><li><span><a href="#1.3.-Counting-ocurrences-in-tuples" data-toc-modified-id="1.3.-Counting-ocurrences-in-tuples-1.1.3"><span class="toc-item-num">1.1.3&nbsp;&nbsp;</span>1.3. Counting ocurrences in tuples</a></span></li><li><span><a href="#1.4.-Searching-for-an-item-in-a-tuple" data-toc-modified-id="1.4.-Searching-for-an-item-in-a-tuple-1.1.4"><span class="toc-item-num">1.1.4&nbsp;&nbsp;</span>1.4. Searching for an item in a tuple</a></span></li><li><span><a href="#1.5.-Slicing-in-tuples" data-toc-modified-id="1.5.-Slicing-in-tuples-1.1.5"><span class="toc-item-num">1.1.5&nbsp;&nbsp;</span>1.5. Slicing in tuples</a></span></li><li><span><a href="#1.6.-Functions-can-return-tuples" data-toc-modified-id="1.6.-Functions-can-return-tuples-1.1.6"><span class="toc-item-num">1.1.6&nbsp;&nbsp;</span>1.6. Functions can return tuples</a></span></li><li><span><a href="#1.7.-Swapping-pairs-with-tuples-is-fun!" data-toc-modified-id="1.7.-Swapping-pairs-with-tuples-is-fun!-1.1.7"><span class="toc-item-num">1.1.7&nbsp;&nbsp;</span>1.7. Swapping pairs with tuples is fun!</a></span></li><li><span><a href="#1.8.-Tuples-are-inmutable" data-toc-modified-id="1.8.-Tuples-are-inmutable-1.1.8"><span class="toc-item-num">1.1.8&nbsp;&nbsp;</span>1.8. Tuples are inmutable</a></span></li></ul></li><li><span><a href="#2.-[0]-Lists" data-toc-modified-id="2.-[0]-Lists-1.2"><span class="toc-item-num">1.2&nbsp;&nbsp;</span>2. [0] <a href="https
Step1:  1.2. Tuple definition
And some timing ... 
Step2:  1.3. Counting ocurrences in tuples
Step3:  1.4. Searching for an item in a tuple
Step4:  1.5. Slicing in tuples
Step5:  1.6. Functions can return tuples
Step6:  1.7. Swapping pairs with tuples is fun!
Step7:  1.8. Tuples are inmutable
They can not grow
Step8:  ... or be changed
Step9:  Tuples are inmutable!
Step10:  2. [0] Lists
A list is a data (usually dynamic) structure that holds a collection of objects, which can have different types. Internally, a list is represented as an array, therefore, lists are fast for appending and for set/pop/getting an item, and slow for removing an internal item.
Step11:  2.1 [1] (Of course) lists are objects
Step12:  (Tuples are about three times faster)
Step13:  2.2 [0] Appending items to a list (O(1))
Step14:  Python lists can be "promiscuous"
Step15:  2.3 [0] Inserting items (O(n))
Step16:  2.4 [0] Deleting items from a list by content (O(n)))
Step17:  2.4 [0] Deleting items from the begin of the list (O(1)))
Step18:  2.4 [0] Deleting items from the end of the list (O(1)))
Step19:  2.5 [0] Sorting the elements of a list (O(n log n))
Step20:  2.6 [1] Erasing all list items (O(1))
Step21:  2.7 [0] List slicing (O(s))
Step22:  2.8 [1] Defining lists with list comprehensions
Step23:  2.9 [1] Lists are mutable objects
Lists can be modified "in-place".
Step24:  3. [0]  Sets
Sets are implemented as hash table of (unordered) objects, therefore sets are good for get/set/delete/searching items and bad for . Sets do not support indexing, slicing, or other sequence-like behavior.
Step25:  3.2. [0] Sets can grow (O(1))
Step26:  3.3. [0] Sets can not contain dupplicate objects
Step27:  3.4. [1] Sets can not contain mutable objects
Mutable objects can not be hashed 
Step28:  3.5 [0] Intersection of sets (O(min(len(s), len(t)))
Step29:  3.6 [0] Union of sets (O(len(s)+len(t)))
Step30:  3.7. [0] Sets are MUCH more efficient for searching by content than lists
Step31:  4 [0] Dictionaries
Dictionaries are sets where each element (a key) has associated an object (a value). In fact, sets can be seen as dictionaries where the elments have not associations. As sets, dictionaries are efficient for indexing by keys.
Step32:  4.1 [0] Static definition of a dictionary
Step33:  4.2 [0] Indexing of a dictionary by a key (O(1))
Step34:  4.3 [0] Testing if a key is the dictionary (O(1))
Step35:  4.4 [1] Getting the keys (O(n))
Step36:  4.5 [1] Getting the values (O(n))
Step37:  4.4 [1] Determining the position of a key in a dictionary (O(n))
Step38:  4.6 [0] Inserting a new entry (O(1))
Step39:  [0] 4.7 Deleting an entry (O(1))
Step40:  4.8 [1] Dictionaries are mutable
Step41:  4.9 [0] Looping a dictionary (O(n))
Step42:  5. Bytes
A raw bytes sequence type.
5.1. Creation of bytes sequence
Step43:  5.2. Indexing in a bytes sequence
Step44:  5.3. Concatenation of bytes sequences
Step45:  5.4. Bytes are inmutable
Step46:  6. Bytearray
Bytearray is a mutable implementation of an array of bytes. Therefore, appending data to a bytearray object is much faster than to a bytes object because in this last case, every append implies to create (and destroy the previous) new bytes object.
Step47:  7. Arrays
Step48:  Element access
Step49:  Slice access
Step50:  Appending elements
Step51:  Concatenating arrays
Step52:  Deleting elements
<ASSISTANT_TASK:>
Python Code:
print(type(()))
help(())
Explanation: <h1>Table of Contents<span class="tocSkip"></span></h1>
<div class="toc"><ul class="toc-item"><li><span><a href="#Containers" data-toc-modified-id="Containers-1"><span class="toc-item-num">1&nbsp;&nbsp;</span>Containers</a></span><ul class="toc-item"><li><span><a href="#1.-Tuples" data-toc-modified-id="1.-Tuples-1.1"><span class="toc-item-num">1.1&nbsp;&nbsp;</span>1. Tuples</a></span><ul class="toc-item"><li><span><a href="#1.1-Tuples-are-(as-the-rest-of-elements-of-Python)-objects" data-toc-modified-id="1.1-Tuples-are-(as-the-rest-of-elements-of-Python)-objects-1.1.1"><span class="toc-item-num">1.1.1&nbsp;&nbsp;</span>1.1 Tuples are (as the rest of elements of Python) objects</a></span></li><li><span><a href="#1.2.-Tuple-definition" data-toc-modified-id="1.2.-Tuple-definition-1.1.2"><span class="toc-item-num">1.1.2&nbsp;&nbsp;</span>1.2. Tuple definition</a></span></li><li><span><a href="#1.3.-Counting-ocurrences-in-tuples" data-toc-modified-id="1.3.-Counting-ocurrences-in-tuples-1.1.3"><span class="toc-item-num">1.1.3&nbsp;&nbsp;</span>1.3. Counting ocurrences in tuples</a></span></li><li><span><a href="#1.4.-Searching-for-an-item-in-a-tuple" data-toc-modified-id="1.4.-Searching-for-an-item-in-a-tuple-1.1.4"><span class="toc-item-num">1.1.4&nbsp;&nbsp;</span>1.4. Searching for an item in a tuple</a></span></li><li><span><a href="#1.5.-Slicing-in-tuples" data-toc-modified-id="1.5.-Slicing-in-tuples-1.1.5"><span class="toc-item-num">1.1.5&nbsp;&nbsp;</span>1.5. Slicing in tuples</a></span></li><li><span><a href="#1.6.-Functions-can-return-tuples" data-toc-modified-id="1.6.-Functions-can-return-tuples-1.1.6"><span class="toc-item-num">1.1.6&nbsp;&nbsp;</span>1.6. Functions can return tuples</a></span></li><li><span><a href="#1.7.-Swapping-pairs-with-tuples-is-fun!" data-toc-modified-id="1.7.-Swapping-pairs-with-tuples-is-fun!-1.1.7"><span class="toc-item-num">1.1.7&nbsp;&nbsp;</span>1.7. Swapping pairs with tuples is fun!</a></span></li><li><span><a href="#1.8.-Tuples-are-inmutable" data-toc-modified-id="1.8.-Tuples-are-inmutable-1.1.8"><span class="toc-item-num">1.1.8&nbsp;&nbsp;</span>1.8. Tuples are inmutable</a></span></li></ul></li><li><span><a href="#2.-[0]-Lists" data-toc-modified-id="2.-[0]-Lists-1.2"><span class="toc-item-num">1.2&nbsp;&nbsp;</span>2. [0] <a href="https://docs.python.org/3.7/library/stdtypes.html#sequence-types-list-tuple-range" target="_blank">Lists</a></a></span><ul class="toc-item"><li><span><a href="#2.1-[1]-(Of-course)-lists-are-objects" data-toc-modified-id="2.1-[1]-(Of-course)-lists-are-objects-1.2.1"><span class="toc-item-num">1.2.1&nbsp;&nbsp;</span>2.1 [1] (Of course) lists are objects</a></span></li><li><span><a href="#2.2-[0]-Appending-items-to-a-list-(O(1))" data-toc-modified-id="2.2-[0]-Appending-items-to-a-list-(O(1))-1.2.2"><span class="toc-item-num">1.2.2&nbsp;&nbsp;</span>2.2 [0] Appending items to a list (O(1))</a></span></li><li><span><a href="#2.3-[0]-Inserting-items-(O(n))" data-toc-modified-id="2.3-[0]-Inserting-items-(O(n))-1.2.3"><span class="toc-item-num">1.2.3&nbsp;&nbsp;</span>2.3 [0] Inserting items (O(n))</a></span></li><li><span><a href="#2.4-[0]-Deleting-items-from-a-list-by-content-(O(n)))" data-toc-modified-id="2.4-[0]-Deleting-items-from-a-list-by-content-(O(n)))-1.2.4"><span class="toc-item-num">1.2.4&nbsp;&nbsp;</span>2.4 [0] Deleting items from a list by content (O(n)))</a></span></li><li><span><a href="#2.4-[0]-Deleting-items-from-the-begin-of-the-list-(O(1)))" data-toc-modified-id="2.4-[0]-Deleting-items-from-the-begin-of-the-list-(O(1)))-1.2.5"><span class="toc-item-num">1.2.5&nbsp;&nbsp;</span>2.4 [0] Deleting items from the begin of the list (O(1)))</a></span></li><li><span><a href="#2.4-[0]-Deleting-items-from-the-end-of-the-list-(O(1)))" data-toc-modified-id="2.4-[0]-Deleting-items-from-the-end-of-the-list-(O(1)))-1.2.6"><span class="toc-item-num">1.2.6&nbsp;&nbsp;</span>2.4 [0] Deleting items from the end of the list (O(1)))</a></span></li><li><span><a href="#2.5-[0]-Sorting-the-elements-of-a-list-(O(n-log-n))" data-toc-modified-id="2.5-[0]-Sorting-the-elements-of-a-list-(O(n-log-n))-1.2.7"><span class="toc-item-num">1.2.7&nbsp;&nbsp;</span>2.5 [0] Sorting the elements of a list (O(n log n))</a></span></li><li><span><a href="#2.6-[1]-Erasing-all-list-items-(O(1))" data-toc-modified-id="2.6-[1]-Erasing-all-list-items-(O(1))-1.2.8"><span class="toc-item-num">1.2.8&nbsp;&nbsp;</span>2.6 [1] Erasing all list items (O(1))</a></span></li><li><span><a href="#2.7-[0]-List-slicing-(O(s))" data-toc-modified-id="2.7-[0]-List-slicing-(O(s))-1.2.9"><span class="toc-item-num">1.2.9&nbsp;&nbsp;</span>2.7 [0] List slicing (O(s))</a></span></li><li><span><a href="#2.8-[1]-Defining-lists-with-list-comprehensions:" data-toc-modified-id="2.8-[1]-Defining-lists-with-list-comprehensions:-1.2.10"><span class="toc-item-num">1.2.10&nbsp;&nbsp;</span>2.8 [1] Defining lists with <a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk" target="_blank"><em>list comprehensions</em></a>:</a></span></li><li><span><a href="#2.9-[1]-Lists-are-mutable-objects" data-toc-modified-id="2.9-[1]-Lists-are-mutable-objects-1.2.11"><span class="toc-item-num">1.2.11&nbsp;&nbsp;</span>2.9 [1] Lists are mutable objects</a></span></li></ul></li><li><span><a href="#3.-[0]--Sets" data-toc-modified-id="3.-[0]--Sets-1.3"><span class="toc-item-num">1.3&nbsp;&nbsp;</span>3. [0]  <a href="https://docs.python.org/3.7/library/stdtypes.html#set-types-set-frozenset" target="_blank">Sets</a></a></span><ul class="toc-item"><li><span><a href="#3.2.-[0]-Sets-can-grow-(O(1))" data-toc-modified-id="3.2.-[0]-Sets-can-grow-(O(1))-1.3.1"><span class="toc-item-num">1.3.1&nbsp;&nbsp;</span>3.2. [0] Sets can grow (O(1))</a></span></li><li><span><a href="#3.3.-[0]-Sets-can-not-contain-dupplicate-objects" data-toc-modified-id="3.3.-[0]-Sets-can-not-contain-dupplicate-objects-1.3.2"><span class="toc-item-num">1.3.2&nbsp;&nbsp;</span>3.3. [0] Sets can not contain dupplicate objects</a></span></li><li><span><a href="#3.4.-[1]-Sets-can-not-contain-mutable-objects" data-toc-modified-id="3.4.-[1]-Sets-can-not-contain-mutable-objects-1.3.3"><span class="toc-item-num">1.3.3&nbsp;&nbsp;</span>3.4. [1] Sets can not contain mutable objects</a></span></li><li><span><a href="#3.5-[0]-Intersection-of-sets-(O(min(len(s),-len(t)))" data-toc-modified-id="3.5-[0]-Intersection-of-sets-(O(min(len(s),-len(t)))-1.3.4"><span class="toc-item-num">1.3.4&nbsp;&nbsp;</span>3.5 [0] Intersection of sets (O(min(len(s), len(t)))</a></span></li><li><span><a href="#3.6-[0]-Union-of-sets-(O(len(s)+len(t)))" data-toc-modified-id="3.6-[0]-Union-of-sets-(O(len(s)+len(t)))-1.3.5"><span class="toc-item-num">1.3.5&nbsp;&nbsp;</span>3.6 [0] Union of sets (O(len(s)+len(t)))</a></span></li><li><span><a href="#3.7.-[0]-Sets-are-MUCH-more-efficient-for-searching-by-content-than-lists" data-toc-modified-id="3.7.-[0]-Sets-are-MUCH-more-efficient-for-searching-by-content-than-lists-1.3.6"><span class="toc-item-num">1.3.6&nbsp;&nbsp;</span>3.7. [0] Sets are MUCH more <a href="https://wiki.python.org/moin/TimeComplexity" target="_blank">efficient for searching by content</a> than lists</a></span></li></ul></li><li><span><a href="#4-[0]-Dictionaries" data-toc-modified-id="4-[0]-Dictionaries-1.4"><span class="toc-item-num">1.4&nbsp;&nbsp;</span>4 [0] <a href="https://docs.python.org/3.7/library/stdtypes.html#dict" target="_blank">Dictionaries</a></a></span><ul class="toc-item"><li><span><a href="#4.1-[0]-Static-definition-of-a-dictionary" data-toc-modified-id="4.1-[0]-Static-definition-of-a-dictionary-1.4.1"><span class="toc-item-num">1.4.1&nbsp;&nbsp;</span>4.1 [0] Static definition of a dictionary</a></span></li><li><span><a href="#4.2-[0]-Indexing-of-a-dictionary-by-a-key-(O(1))" data-toc-modified-id="4.2-[0]-Indexing-of-a-dictionary-by-a-key-(O(1))-1.4.2"><span class="toc-item-num">1.4.2&nbsp;&nbsp;</span>4.2 [0] Indexing of a dictionary by a key (O(1))</a></span></li><li><span><a href="#4.3-[0]-Testing-if-a-key-is-the-dictionary-(O(1))" data-toc-modified-id="4.3-[0]-Testing-if-a-key-is-the-dictionary-(O(1))-1.4.3"><span class="toc-item-num">1.4.3&nbsp;&nbsp;</span>4.3 [0] Testing if a key is the dictionary (O(1))</a></span></li><li><span><a href="#4.4-[1]-Getting-the-keys-(O(n))" data-toc-modified-id="4.4-[1]-Getting-the-keys-(O(n))-1.4.4"><span class="toc-item-num">1.4.4&nbsp;&nbsp;</span>4.4 [1] Getting the keys (O(n))</a></span></li><li><span><a href="#4.5-[1]-Getting-the-values-(O(n))" data-toc-modified-id="4.5-[1]-Getting-the-values-(O(n))-1.4.5"><span class="toc-item-num">1.4.5&nbsp;&nbsp;</span>4.5 [1] Getting the values (O(n))</a></span></li><li><span><a href="#4.4-[1]-Determining-the-position-of-a-key-in-a-dictionary-(O(n))" data-toc-modified-id="4.4-[1]-Determining-the-position-of-a-key-in-a-dictionary-(O(n))-1.4.6"><span class="toc-item-num">1.4.6&nbsp;&nbsp;</span>4.4 [1] Determining the position of a key in a dictionary (O(n))</a></span></li><li><span><a href="#4.6-[0]-Inserting-a-new-entry-(O(1))" data-toc-modified-id="4.6-[0]-Inserting-a-new-entry-(O(1))-1.4.7"><span class="toc-item-num">1.4.7&nbsp;&nbsp;</span>4.6 [0] Inserting a new entry (O(1))</a></span></li><li><span><a href="#[0]-4.7-Deleting-an-entry-(O(1))" data-toc-modified-id="[0]-4.7-Deleting-an-entry-(O(1))-1.4.8"><span class="toc-item-num">1.4.8&nbsp;&nbsp;</span>[0] 4.7 Deleting an entry (O(1))</a></span></li><li><span><a href="#4.8-[1]-Dictionaries-are-mutable" data-toc-modified-id="4.8-[1]-Dictionaries-are-mutable-1.4.9"><span class="toc-item-num">1.4.9&nbsp;&nbsp;</span>4.8 [1] Dictionaries are mutable</a></span></li><li><span><a href="#4.9-[0]-Looping-a-dictionary-(O(n))" data-toc-modified-id="4.9-[0]-Looping-a-dictionary-(O(n))-1.4.10"><span class="toc-item-num">1.4.10&nbsp;&nbsp;</span>4.9 [0] Looping a dictionary (O(n))</a></span></li></ul></li><li><span><a href="#5.-Bytes" data-toc-modified-id="5.-Bytes-1.5"><span class="toc-item-num">1.5&nbsp;&nbsp;</span>5. <a href="http://python-para-impacientes.blogspot.com.es/2014/07/tipos-de-cadenas-unicode-byte-y.html" target="_blank">Bytes</a></a></span><ul class="toc-item"><li><span><a href="#5.1.-Creation-of-bytes-sequence" data-toc-modified-id="5.1.-Creation-of-bytes-sequence-1.5.1"><span class="toc-item-num">1.5.1&nbsp;&nbsp;</span>5.1. Creation of bytes sequence</a></span></li><li><span><a href="#5.2.-Indexing-in-a-bytes-sequence" data-toc-modified-id="5.2.-Indexing-in-a-bytes-sequence-1.5.2"><span class="toc-item-num">1.5.2&nbsp;&nbsp;</span>5.2. Indexing in a bytes sequence</a></span></li><li><span><a href="#5.3.-Concatenation-of-bytes-sequences" data-toc-modified-id="5.3.-Concatenation-of-bytes-sequences-1.5.3"><span class="toc-item-num">1.5.3&nbsp;&nbsp;</span>5.3. Concatenation of bytes sequences</a></span></li><li><span><a href="#5.4.-Bytes-are-inmutable" data-toc-modified-id="5.4.-Bytes-are-inmutable-1.5.4"><span class="toc-item-num">1.5.4&nbsp;&nbsp;</span>5.4. Bytes are inmutable</a></span></li></ul></li><li><span><a href="#6.-Bytearray" data-toc-modified-id="6.-Bytearray-1.6"><span class="toc-item-num">1.6&nbsp;&nbsp;</span>6. <a href="http://ze.phyr.us/bytearray/" target="_blank">Bytearray</a></a></span></li><li><span><a href="#7.-Arrays" data-toc-modified-id="7.-Arrays-1.7"><span class="toc-item-num">1.7&nbsp;&nbsp;</span>7. <a href="https://docs.python.org/3/library/array.html" target="_blank">Arrays</a></a></span><ul class="toc-item"><li><span><a href="#Element-access" data-toc-modified-id="Element-access-1.7.1"><span class="toc-item-num">1.7.1&nbsp;&nbsp;</span>Element access</a></span></li><li><span><a href="#Slice-access" data-toc-modified-id="Slice-access-1.7.2"><span class="toc-item-num">1.7.2&nbsp;&nbsp;</span>Slice access</a></span></li><li><span><a href="#Appending-elements" data-toc-modified-id="Appending-elements-1.7.3"><span class="toc-item-num">1.7.3&nbsp;&nbsp;</span>Appending elements</a></span></li><li><span><a href="#Concatenating-arrays" data-toc-modified-id="Concatenating-arrays-1.7.4"><span class="toc-item-num">1.7.4&nbsp;&nbsp;</span>Concatenating arrays</a></span></li><li><span><a href="#Deleting-elements" data-toc-modified-id="Deleting-elements-1.7.5"><span class="toc-item-num">1.7.5&nbsp;&nbsp;</span>Deleting elements</a></span></li></ul></li></ul></li></ul></div>
Containers
Tuples.
Lists.
Sets.
Dictionaries.
Bytes.
Bytearrays.
Arrays.
1. Tuples
A tuples groups multiple (possiblely with different types) objects. They can be compared to (static) structures of other languages.
1.1 Tuples are (as the rest of elements of Python) objects
End of explanation
!python -m timeit "x = (1, 'a', 'b', 'a')"
a = (1, 'a', 'b', 'a')
Explanation: 1.2. Tuple definition
And some timing ... :-)
End of explanation
a.count('a')
Explanation: 1.3. Counting ocurrences in tuples
End of explanation
a.index('b')
Explanation: 1.4. Searching for an item in a tuple
End of explanation
a
a[2] # The 3-rd item
a[2:1] # Extract the tuple from the 2-nd item to the 1-st one
a[2:2] # Extract from the 2-nd item to the 2-nd item
a[2:3] # Extract from the 2-nd item to the 3-rd one
a[2:4] # Extract one item more
a[1:] # Extract from the 1-st to the end
a[:] # Extract all items (a==a[:])
Explanation: 1.5. Slicing in tuples
End of explanation
def return_tuple():
    return (1, 'a', 2)
print(return_tuple())
Explanation: 1.6. Functions can return tuples
End of explanation
a = 1; b = 2
print(a, b)
(a, b) = (b, a)
print(a, b)
Explanation: 1.7. Swapping pairs with tuples is fun!
End of explanation
a = (1, 'a')
print(id(a),a)
a += (2,) # This creates a new instance of 'a'
print(id(a),a)
Explanation: 1.8. Tuples are inmutable
They can not grow:
End of explanation
a[1] = 2
Explanation: ... or be changed:
End of explanation
a = 1; b = 2
print('"a" is in', id(a))
t = (a, b)
print('"t" is in', id(t), 'and contains', t)
a = 3
print('"a" is in', id(a))
print('"t" is in', id(t), 'and contains', t)
Explanation: Tuples are inmutable!
End of explanation
help([])
Explanation: 2. [0] Lists
A list is a data (usually dynamic) structure that holds a collection of objects, which can have different types. Internally, a list is represented as an array, therefore, lists are fast for appending and for set/pop/getting an item, and slow for removing an internal item.
End of explanation
print(type([]));
!python -m timeit "x = [1, 'a', 'b', 'a']" # List creation is more expensive than tuple creation
Explanation: 2.1 [1] (Of course) lists are objects
End of explanation
a = [] # Empty list definition
Explanation: (Tuples are about three times faster)
End of explanation
a.append('Hello')
a.append('world!')
a
Explanation: 2.2 [0] Appending items to a list (O(1))
End of explanation
a.append(100)
a
Explanation: Python lists can be "promiscuous":
End of explanation
a.insert(1,'wave!')
a
Explanation: 2.3 [0] Inserting items (O(n))
End of explanation
a.remove('Hello')
a
b = ['a', 'b', 'a']; b.remove('a'); print(b)
Explanation: 2.4 [0] Deleting items from a list by content (O(n)))
End of explanation
a.pop(0)
Explanation: 2.4 [0] Deleting items from the begin of the list (O(1)))
End of explanation
print(a)
a.pop(len(a)-1) # By index, equivalent to "del a[0]"
print(a)
Explanation: 2.4 [0] Deleting items from the end of the list (O(1)))
End of explanation
a = []
a.append('c')
a.append('b')
a.append('a')
a
a.sort()
a
a.reverse()
a
# Indexing
print(a[1])   # Second element
print(a[-1])  # Last element
print(a[100]) # Error
a+a
a*3
a[::-1]
x = [1,2,3,2,1] # Palindrome?
x[::-1] == x
Explanation: 2.5 [0] Sorting the elements of a list (O(n log n))
End of explanation
a.clear()
a
Explanation: 2.6 [1] Erasing all list items (O(1))
End of explanation
a.append('Hello')
print(a, a[0])
a.append(1)
a.append(('a',2))
a.append('world!')
a
print(a[1:1], a[1:2], a[1:3], a[1:], a[:], a[1:3:2])
Explanation: 2.7 [0] List slicing (O(s))
End of explanation
[x**2 for x in range(10)]
# http://stackoverflow.com/questions/31045518/finding-prime-numbers-using-list-comprehention
[x for x in range(2, 2000) if all(x % y != 0 for y in range(2, int(x ** 0.5) + 1))]
l = [[x+y for x in range(10)] for y in range(10)]
l
l[1][2]
10 in l
10 in l[1]
# Lists of lists
x = [[1,2],[2,3,4],['a']]
x
Explanation: 2.8 [1] Defining lists with list comprehensions:
End of explanation
l = [2,3]
id(l)
l[1] = 4
l
id(l)
Explanation: 2.9 [1] Lists are mutable objects
Lists can be modified "in-place".
End of explanation
a = {1, 2, 'a', (1, 2)}
a
print(type(a))
help(a)
Explanation: 3. [0]  Sets
Sets are implemented as hash table of (unordered) objects, therefore sets are good for get/set/delete/searching items and bad for . Sets do not support indexing, slicing, or other sequence-like behavior.
End of explanation
a.add('a')
print(a)
Explanation: 3.2. [0] Sets can grow (O(1))
End of explanation
a.add('a')
print(a)
Explanation: 3.3. [0] Sets can not contain dupplicate objects
End of explanation
a = set()
a.add([1,2]) # Sets can not contain lists
a = set() # Empty set
a.add({1,2,3}) # Sets can not contain sets
Explanation: 3.4. [1] Sets can not contain mutable objects
Mutable objects can not be hashed :-(
End of explanation
a = {1,2,3}
b = {2,3,4}
a.intersection(b)
Explanation: 3.5 [0] Intersection of sets (O(min(len(s), len(t)))
End of explanation
a.union(b)
Explanation: 3.6 [0] Union of sets (O(len(s)+len(t)))
End of explanation
a = set(range(1000))
print(a)
%timeit '0' in a
a = list(range(1000))
print(a)
%timeit '0' in a
Explanation: 3.7. [0] Sets are MUCH more efficient for searching by content than lists
End of explanation
help({})
Explanation: 4 [0] Dictionaries
Dictionaries are sets where each element (a key) has associated an object (a value). In fact, sets can be seen as dictionaries where the elments have not associations. As sets, dictionaries are efficient for indexing by keys.
End of explanation
a = {'Macinstosh':'OSX', 'PC':'Windows', 'Macintosh-Linux':'Linux', 'PC-Linux':'Linux'}
a
Explanation: 4.1 [0] Static definition of a dictionary
End of explanation
a['PC']
Explanation: 4.2 [0] Indexing of a dictionary by a key (O(1))
End of explanation
'PC-Linux' in a
Explanation: 4.3 [0] Testing if a key is the dictionary (O(1))
End of explanation
a.keys()
Explanation: 4.4 [1] Getting the keys (O(n))
End of explanation
a.values()
Explanation: 4.5 [1] Getting the values (O(n))
End of explanation
list(a.keys()).index("Macintosh-Linux")
for i in a.keys():
    print(i)
Explanation: 4.4 [1] Determining the position of a key in a dictionary (O(n))
End of explanation
a['Celullar'] = "Android"
a
Explanation: 4.6 [0] Inserting a new entry (O(1))
End of explanation
del a['Celullar']
a
# Modifiying an entry
a.update({"PC": "Windows 10"})
a
Explanation: [0] 4.7 Deleting an entry (O(1))
End of explanation
id(a)
a['Macintosh-Linux'] = 'Linux for the Mac'
a
id(a)
Explanation: 4.8 [1] Dictionaries are mutable
End of explanation
for i in a:
    print(i, a[i])
for i in a.values():
    print(i)
for i in a.items():
    print(i)
Explanation: 4.9 [0] Looping a dictionary (O(n))
End of explanation
a = b'hello'
print(type(a))
print(a)
Explanation: 5. Bytes
A raw bytes sequence type.
5.1. Creation of bytes sequence
End of explanation
chr(a[1])
Explanation: 5.2. Indexing in a bytes sequence
End of explanation
b = b'world!'
print('"b" is in', id(b))
c = a + b' ' + b
print(c)
Explanation: 5.3. Concatenation of bytes sequences
End of explanation
a = b'abc'
print(id(a))
a += b'efg'
print(id(a))
Explanation: 5.4. Bytes are inmutable
End of explanation
%%timeit x = b''
x += b'x'
%%timeit x = bytearray()
x.extend(b'x')
# Array of bytes = 0
x = bytearray(10)
x
len(x)
for i in range(len(x)):
    x[i] += 1
x
# A byte in Python is a 0 <= value <= 255.
x[1] = -1
# A bytearray can be created from a list
x = bytearray([1,2,3])
x
import sys
x = bytearray(sys.stdin.read(5).encode())
x
Explanation: 6. Bytearray
Bytearray is a mutable implementation of an array of bytes. Therefore, appending data to a bytearray object is much faster than to a bytes object because in this last case, every append implies to create (and destroy the previous) new bytes object.
End of explanation
import array as arr
a = arr.array('d', [1.1, 3.5, 4.5])
print(a)
Explanation: 7. Arrays
End of explanation
a[1]
a[1] = 4.0
a
Explanation: Element access
End of explanation
a[1:2]
Explanation: Slice access
End of explanation
a.append(5.0)
a
Explanation: Appending elements
End of explanation
a.extend([5.0, 6.0, 7.0])
a
a += arr.array('d', [1.1, 4.0, 4.5])
a
Explanation: Concatenating arrays
End of explanation
# By value
a.remove(4.0)
a
# By index
a.pop(3)
a
Explanation: Deleting elements
End of explanation
<END_TASK>