<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Built-In Data Structures
Python also has several built-in compound types, which act as containers for other types.
| Type Name | Example                   |Description                            |
|-----------|---------------------------|---------------------------------------|
| list  | [1, 2, 3]             | Ordered collection                    |
| tuple | (1, 2, 3)             | Immutable ordered collection          |
| dict  | {'a'
Step1:  Lists have a number of useful properties and methods available to them.
Step2:  One of the powerful features of Python's compound objects is that they can contain a mix of objects of any type.
Step3:  This flexibility is a consequence of Python's dynamic type system.
Creating such a mixed sequence in a statically-typed language like C can be much more of a headache!
We see that lists can even contain other lists as elements.
Such type flexibility is an essential piece of what makes Python code relatively quick and easy to write.
List indexing and slicing
Python provides access to elements in compound types through indexing for single elements, and slicing for multiple elements.
Step4:  Python uses zero-based indexing, so we can access the first and second element in using the following syntax
Step5:  Elements at the end of the list can be accessed with negative numbers, starting from -1
Step6:  You can visualize this indexing scheme this way
Step7:  we can equivalently write
Step8:  Similarly, if we leave out the last index, it defaults to the length of the list.
Thus, the last three elements can be accessed as follows
Step9:  Finally, it is possible to specify a third integer that represents the step size; for example, to select every second element of the list, we can write
Step10:  A particularly useful version of this is to specify a negative step, which will reverse the array
Step11:  Both indexing and slicing can be used to set elements as well as access them.
The syntax is as you would expect
Step12:  A very similar slicing syntax is also used in other data containers, such as NumPy arrays, as we will see in Day 2 sessions.
Tuples
Tuples are in many ways similar to lists, but they are defined with parentheses and cannot be changed!
Step13:  They can also be defined without any brackets at all
Step14:  Like the lists discussed before, tuples have a length, and individual elements can be extracted using square-bracket indexing
Step15:  The main distinguishing feature of tuples is that they are immutable
Step16:  Items are accessed and set via the indexing syntax used for lists and tuples, except here the index is not a zero-based order but valid key in the dictionary
Step17:  New items can be added to the dictionary using indexing as well
Step18:  Keep in mind that dictionaries do not maintain any order for the input parameters.
Sets
The 4th basic data container is the set, which contains unordered collections of unique items.
They are defined much like lists and tuples, except they use the curly brackets of dictionaries.
They do not contain duplicate entries. Which means they are significantly faster than lists!
http
Step19:  If you're familiar with the mathematics of sets, you'll be familiar with operations like the union, intersection, difference, symmetric difference, and others.
Python's sets have all of these operations built-in, via methods or operators.
For each, we'll show the two equivalent methods
<ASSISTANT_TASK:>
Python Code:
a = [2, 3, 5, 7]
Explanation: Built-In Data Structures
Python also has several built-in compound types, which act as containers for other types.
| Type Name | Example                   |Description                            |
|-----------|---------------------------|---------------------------------------|
| list  | [1, 2, 3]             | Ordered collection                    |
| tuple | (1, 2, 3)             | Immutable ordered collection          |
| dict  | {'a':1, 'b':2, 'c':3} | Unordered (key,value) mapping         |
| set   | {1, 2, 3}             | Unordered collection of unique values |
Note, round, square, and curly brackets have distinct meanings.
Lists
Lists are the basic ordered and mutable data collection type in Python.
End of explanation
# Length of a list
len(a)
# Append a value to the end
a.append(11)
a
# Addition concatenates lists
a + [13, 17, 19]
# sort() method sorts in-place
a = [2, 5, 1, 6, 3, 4]
a.sort()
a
Explanation: Lists have a number of useful properties and methods available to them.
End of explanation
a = [1, 'two', 3.14, [0, 3, 5]]
a
Explanation: One of the powerful features of Python's compound objects is that they can contain a mix of objects of any type.
End of explanation
a = [2, 3, 5, 7, 11]
Explanation: This flexibility is a consequence of Python's dynamic type system.
Creating such a mixed sequence in a statically-typed language like C can be much more of a headache!
We see that lists can even contain other lists as elements.
Such type flexibility is an essential piece of what makes Python code relatively quick and easy to write.
List indexing and slicing
Python provides access to elements in compound types through indexing for single elements, and slicing for multiple elements.
End of explanation
a[0]
a[1]
Explanation: Python uses zero-based indexing, so we can access the first and second element in using the following syntax:
End of explanation
a[-1]
a[-2]
Explanation: Elements at the end of the list can be accessed with negative numbers, starting from -1:
End of explanation
a[0:3]
Explanation: You can visualize this indexing scheme this way:
Here values in the list are represented by large numbers in the squares; list indices are represented by small numbers above and below.
In this case, L[2] returns 5, because that is the next value at index 2.
Where indexing is a means of fetching a single value from the list, slicing is a means of accessing multiple values in sub-lists.
It uses a colon to indicate the start point (inclusive) and end point (non-inclusive) of the sub-array.
For example, to get the first three elements of the list, we can write:
End of explanation
a[:3]
Explanation: we can equivalently write:
End of explanation
a[-3:]
Explanation: Similarly, if we leave out the last index, it defaults to the length of the list.
Thus, the last three elements can be accessed as follows:
End of explanation
a[::2]  # equivalent to a[0:len(a):2]
Explanation: Finally, it is possible to specify a third integer that represents the step size; for example, to select every second element of the list, we can write:
End of explanation
a[::-1]
Explanation: A particularly useful version of this is to specify a negative step, which will reverse the array:
End of explanation
a[0] = 100
print(a)
a[1:3] = [55, 56]
print(a)
Explanation: Both indexing and slicing can be used to set elements as well as access them.
The syntax is as you would expect:
End of explanation
t = (1, 2, 3)
Explanation: A very similar slicing syntax is also used in other data containers, such as NumPy arrays, as we will see in Day 2 sessions.
Tuples
Tuples are in many ways similar to lists, but they are defined with parentheses and cannot be changed!
End of explanation
t = 1, 2, 3
print(t)
Explanation: They can also be defined without any brackets at all:
End of explanation
len(t)
t[0]
Explanation: Like the lists discussed before, tuples have a length, and individual elements can be extracted using square-bracket indexing:
End of explanation
numbers = {'one':1, 'two':2, 'three':3}
# or
numbers = dict(one=1, two=2, three=2)
Explanation: The main distinguishing feature of tuples is that they are immutable: this means that once they are created, their size and contents cannot be changed:
Tuples are often used in a Python program; e.g. in functions that have multiple return values.
Dictionaries
Dictionaries are extremely flexible mappings of keys to values, and form the basis of much of Python's internal implementation.
They can be created via a comma-separated list of key:value pairs within curly braces:
End of explanation
# Access a value via the key
numbers['two']
Explanation: Items are accessed and set via the indexing syntax used for lists and tuples, except here the index is not a zero-based order but valid key in the dictionary:
End of explanation
# Set a new key:value pair
numbers['ninety'] = 90
print(numbers)
Explanation: New items can be added to the dictionary using indexing as well:
End of explanation
primes = {2, 3, 5, 7}
odds = {1, 3, 5, 7, 9}
a = {1, 1, 2}
a
Explanation: Keep in mind that dictionaries do not maintain any order for the input parameters.
Sets
The 4th basic data container is the set, which contains unordered collections of unique items.
They are defined much like lists and tuples, except they use the curly brackets of dictionaries.
They do not contain duplicate entries. Which means they are significantly faster than lists!
http://stackoverflow.com/questions/2831212/python-sets-vs-lists
End of explanation
# union: items appearing in either
primes | odds      # with an operator
primes.union(odds) # equivalently with a method
# intersection: items appearing in both
primes & odds             # with an operator
primes.intersection(odds) # equivalently with a method
# difference: items in primes but not in odds
primes - odds           # with an operator
primes.difference(odds) # equivalently with a method
# symmetric difference: items appearing in only one set
primes ^ odds                     # with an operator
primes.symmetric_difference(odds) # equivalently with a method
Explanation: If you're familiar with the mathematics of sets, you'll be familiar with operations like the union, intersection, difference, symmetric difference, and others.
Python's sets have all of these operations built-in, via methods or operators.
For each, we'll show the two equivalent methods:
End of explanation
<END_TASK>