In this example we have two ways to access to the list ``[1, 2]``.

If we modify the state of the list itself, but not the references to this object, then the two variables ``x`` and ``y`` still reference the list containing

``[1, 2, 3, 4]``.

Exercise

--------

wihout using python shell, what is the results of the following statements:

.. note::

wihout using python shell, what is the results of the following statements:

.. note::

sum is a function which return the sum of each elements of a list.

::

x = [1, 2, 3, 4]

x[3] = -4 # what is the value of x now ?

y = sum(x)/len(x) #what is the value of y ? why ?

y = 0.5

.. warning::

...

...

@@ -130,37 +131,37 @@ Draw the representation in memory of the following expressions. ::

y = x[1]

y[2] = 'z'

# what is the value of x ?

.. figure:: _static/figs/list_2-1.png

:width: 400px

:alt: set

:figclass: align-center

.. container:: clearer

.. image :: _static/figs/spacer.png

When we execute *y = x[1]*, we create ``y`` wich reference the list ``['a', 'b', 'c']``.

This list has 2 references on it: ``y`` and ``x[1]`` .

.. figure:: _static/figs/list_2-2.png

:width: 400px

:alt: set

:figclass: align-center

.. container:: clearer

.. image :: _static/figs/spacer.png

This object is a list so it is a mutable object.

So we can access **and** modify it by the two ways ``y`` or ``x[1]`` ::

x = [1, ['a','b','z'], 3, 4]

Exercise

--------

...

...

@@ -170,12 +171,12 @@ from the list l = [1, 2, 3, 4, 5, 6, 7, 8, 9] generate 2 lists l1 containing all

l1 = l[::2]

l2 = l[1::2]

Exercise

--------

generate a list containing all codons.

pseudocode:

"""""""""""

...

...

@@ -197,14 +198,14 @@ first implementation:

python -i codons.py

>>> codons = all_codons()

:download:`codons.py <_static/code/codons.py>` .

:download:`codons.py <_static/code/codons.py>`.

second implementation:

""""""""""""""""""""""

Mathematically speaking the generation of all codons can be the cartesian product

between 3 vectors 'acgt'.

between 3 vectors 'acgt'.

In python there is a function to do that in ``itertools module``: `https://docs.python.org/3/library/itertools.html#itertools.product <product>`_

...

...

@@ -216,14 +217,14 @@ In python there is a function to do that in ``itertools module``: `https://docs.