{"id":2110,"date":"2026-02-03T07:14:00","date_gmt":"2026-02-03T06:14:00","guid":{"rendered":"https:\/\/labodemaths.fr\/WordPress3\/?p=2110"},"modified":"2026-02-12T16:48:14","modified_gmt":"2026-02-12T15:48:14","slug":"nsi2022-2023les-listes-en-python","status":"publish","type":"post","link":"https:\/\/labodemaths.fr\/WordPress3\/nsi2022-2023les-listes-en-python\/","title":{"rendered":"NSI: Les listes en Python"},"content":{"rendered":"\n<div class=\"wp-block-file\"><a href=\"https:\/\/labodemaths.fr\/WordPress3\/wp-content\/uploads\/2023\/01\/Les_listes.pdf\">Les_listes<\/a><a href=\"https:\/\/labodemaths.fr\/WordPress3\/wp-content\/uploads\/2023\/01\/Les_listes.pdf\" class=\"wp-block-file__button\" download>T\u00e9l\u00e9charger<\/a><\/div>\n\n\n\n<h3>Exercice 1<\/h3>\n\n\n\n<ol><li>On consid\u00e8re les listes ci-dessous d\u00e9finies en extension :<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt;&gt; a=&#91;0,2,4,6,8,10]\n&gt;&gt;&gt; b=&#91;0,1,4,9,16,25,36]\n&gt;&gt;&gt; c=&#91;10,9,8,7,6,5,4,3,2]<\/code><\/pre>\n\n\n\n<p>D\u00e9terminer comment les d\u00e9finir par compr\u00e9hension.<\/p>\n\n\n\n<p>Que retournent les commandes ci-dessous  ?<\/p>\n\n\n\n<h3>Exercice 2<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt;&gt;&#91;i+j for i in &#91;3,1,2] for j in &#91;2,1]]\n&gt;&gt;&gt;&#91;i+j for j in &#91;1,3] for i in &#91;1,0,2] ]\n&gt;&gt;&gt;&#91;&#91;i+j for i in range(3)] for j in range(2)]<\/code><\/pre>\n\n\n\n<h3>Exercice 3<\/h3>\n\n\n\n<p>Ecrire une fonction permettant de remplir al\u00e9atoirement un liste de longueur n par des nombres entiers compris entre 0 et 100.<br>La fonction utilisera une liste en compr\u00e9hension et la m\u00e9thode randint() du module random.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt;&gt; # par exemple\n&gt;&gt;&gt; liste_aleatoire(5)\n&gt;&gt;&gt; &#91;6,19,54,27,4]<\/code><\/pre>\n\n\n\n<h3>Exercice 4<\/h3>\n\n\n\n<p>Ecrire une fonction inverse retournant la liste invers\u00e9e d&rsquo;un liste pass\u00e9e en param\u00e8tre.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt;&gt; # par exemple\n&gt;&gt;&gt; a=&#91;1,7]\n&gt;&gt;&gt; inverse_liste(a)\n&gt;&gt;&gt; &#91;7,1]<\/code><\/pre>\n\n\n\n<h3>Exercice 5<\/h3>\n\n\n\n<p>Ecrire une fonction triee() permettant de d\u00e9terminer si une liste est tri\u00e9e par ordre croissant<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt;&gt; a=&#91;7,3,6]\n&gt;&gt;&gt; triee(a)\nFalse\n&gt;&gt;&gt; b=&#91;5,8,15]\n&gt;&gt;&gt; triee(b)\nTrue<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><\/code><\/pre>\n\n\n\n<p class=\"has-very-light-gray-color has-vivid-cyan-blue-background-color has-text-color has-background\">Proposition correction exercices 3 \u00e0 5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from random import *\r\n\r\ndef liste_aleatoire(n):\r\n    return &#91;randint(0,100) for i in range(n)]\r\n\r\ndef liste_aleatoire1(n):\r\n    retour=&#91;]\r\n    for i in range(n):\r\n        retour.append(randint(0,100))\r\n    return retour\r\n\r\ndef inverse_liste(liste):\r\n    '''\r\n    >>>inverse_liste(&#91;5,8,12])\r\n    &#91;12,8,5]\r\n    '''\r\n    retour=&#91;]\r\n    for i in range(len(liste)-1,-1,-1):\r\n        retour.append(liste&#91;i])\r\n    return retour\r\n\r\n\r\ndef triee(liste):\r\n    '''\r\n    indique si une liste est tri\u00e9e par ordre\r\n    croissant\r\n    >>>triee(&#91;4,8,12])\r\n    True\r\n    >>>triee(&#91;4,2,12])\r\n    False\r\n    '''\r\n    for i in range(len(liste)-1):\r\n        if liste&#91;i]>liste&#91;i+1]:\r\n            return False\r\n    return True\r\n    \r\ndef triee1(liste):\r\n    '''\r\n    indique si une liste est tri\u00e9e par ordre\r\n    croissant\r\n    >>>triee1(&#91;4,8,12])\r\n    True\r\n    >>>triee1(&#91;4,2,12])\r\n    False\r\n    '''   \r\n    return liste==sorted(liste)\r\n\r\ndef fusion(list1,list2):\r\n    '''\r\n    >>>fusion(&#91;1,2,5],&#91;3,12,3])\r\n    &#91;1,2,5,3,12,3]\r\n    '''\r\n    return list1+list2\r\n\r\ndef fusion1(list1,list2):\r\n    retour=&#91;]\r\n    for val in list1:\r\n        retour.append(val)\r\n    for val in list2:\r\n        retour.append(val)\r\n    return retour\r\n\r\ndef negatif(liste):\r\n    '''\r\n    >>>negatif(&#91;1,0,1,1,1,0,1])\r\n    &#91;0,1,0,0,0,1,0]\r\n    '''\r\n    retour=&#91;]\r\n    for val in liste:\r\n        if val==0:\r\n            retour.append(1)\r\n        else:\r\n            retour.append(0)\r\n    return retour\r\n\r\ndef maximum_sans_max(liste):\r\n    '''\r\n    >>>maximum_sans_max(&#91;8,5,3])\r\n    8\r\n    '''\r\n    maxi=liste&#91;0]\r\n    for val in liste:\r\n        if val>maxi:\r\n            maxi=val\r\n    return maxi\r\n\r\n\r\n\r\n\r\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Exercice 1 On consid\u00e8re les listes ci-dessous d\u00e9finies en extension : D\u00e9terminer comment les d\u00e9finir&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/labodemaths.fr\/WordPress3\/nsi2022-2023les-listes-en-python\/\">Read the post<span class=\"screen-reader-text\">NSI: Les listes en Python<\/span><\/a><\/div>\n","protected":false},"author":2,"featured_media":2112,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[57],"tags":[],"_links":{"self":[{"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/posts\/2110"}],"collection":[{"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/comments?post=2110"}],"version-history":[{"count":10,"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/posts\/2110\/revisions"}],"predecessor-version":[{"id":3070,"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/posts\/2110\/revisions\/3070"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/media\/2112"}],"wp:attachment":[{"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/media?parent=2110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/categories?post=2110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/tags?post=2110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}