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

Exercise

--------

--------

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

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

.. note::

.. note::

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

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

::

::

x = [1, 2, 3, 4]

x = [1, 2, 3, 4]

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

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

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

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

y = 0.5

y = 0.5

.. warning::

.. warning::

...

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

...

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

y = x[1]

y = x[1]

y[2] = 'z'

y[2] = 'z'

# what is the value of x ?

# what is the value of x ?

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

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

:width: 400px

:width: 400px

:alt: set

:alt: set

:figclass: align-center

:figclass: align-center

.. container:: clearer

.. container:: clearer

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

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

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

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]`` .

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

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

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

:width: 400px

:width: 400px

:alt: set

:alt: set

:figclass: align-center

:figclass: align-center

.. container:: clearer

.. container:: clearer

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

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

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

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]`` ::

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

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

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

Exercise

Exercise

--------

--------

...

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

...

@@ -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]

l1 = l[::2]

l2 = l[1::2]

l2 = l[1::2]

Exercise

Exercise

--------

--------

generate a list containing all codons.

generate a list containing all codons.

pseudocode:

pseudocode:

"""""""""""

"""""""""""

...

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

...

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

python -i codons.py

python -i codons.py

>>> codons = all_codons()

>>> codons = all_codons()

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

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

second implementation:

second implementation:

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

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

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

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>`_

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.

...

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