From 98e6e3087c574b5b61cb317801c83149da1e1158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bertrand=20N=C3=A9ron?= <bneron@pasteur.fr> Date: Fri, 18 Jul 2014 04:07:00 +0200 Subject: [PATCH] add one exercise and give solution for 2 exercises add schemas for exercises on the lists --- source/Collection_Data_Types.rst | 51 ++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/source/Collection_Data_Types.rst b/source/Collection_Data_Types.rst index 67d6b5d..40de3b7 100644 --- a/source/Collection_Data_Types.rst +++ b/source/Collection_Data_Types.rst @@ -14,9 +14,8 @@ Exercices Exercice -------- -Draw the representation in memory of the following expressions. -what is the data type of each object. - +| Draw the representation in memory of the following expressions. +| what is the data type of each object? :: @@ -25,6 +24,11 @@ what is the data type of each object. y = 3.14 x[1] = 'foo' +.. figure:: _static/figs/list_1.png + :width: 400px + :alt: set + :figclass: align-center + Exercice -------- @@ -57,6 +61,47 @@ How to compute safely the average of a list? :: exercise -------- +Draw the representation in memory of the following expressions. :: + + x = [1, ['a','b','c'], 3, 4] + 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 +-------- + generate a list containing all codons. :: codons = [] -- GitLab