a = {1, 2, 'a', (1, 2)}
a

print(type(a))

help(a)

"""
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>

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
"""


