{"id":2940,"date":"2025-11-13T14:47:36","date_gmt":"2025-11-13T13:47:36","guid":{"rendered":"https:\/\/labodemaths.fr\/WordPress3\/?p=2940"},"modified":"2025-11-18T09:44:34","modified_gmt":"2025-11-18T08:44:34","slug":"nsi2025-2026-dictionnaires","status":"publish","type":"post","link":"https:\/\/labodemaths.fr\/WordPress3\/nsi2025-2026-dictionnaires\/","title":{"rendered":"NSI,2025-2026, Dictionnaires"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#Exercice 1\ndossards={1:\"Lovelace\",2:\"Turing\",3:\"Church\"}\ntemps={\"Turing\":53,\"Lovelace\":45,\"Church\":48}\n\ndef fonction1(dossards,temps):\n    '''\n    &gt;&gt;&gt;associe le numero de dossard au temps\n    sous la forme d'un dictionnaire\n    &gt;&gt;&gt;fonction1(dossards,temps)\n    {1:45,2:53,3:48}\n    '''\n    \n# exercice 2\nalphabet=\"ABCDEFGHIJKLMNOPQRSTUVWXYZ \"\n\ndef creation_cle(alphabet):\n    '''\n    associe \u00e0 chaque lettre une et une seule\n    lettre tir\u00e9e au hasard dans l'aphabet donn\u00e9\n    renvoie la reponse sous la forme d'un dictionnaire\n    &gt;&gt;&gt;creation_cle(alphabet)\n    {\"A\":\"Q\",\"B\":Z,.............,\" \":E}\n    '''\n    \ndef codage(texte,cle):\n    '''\n    code un texte en rempla\u00e7ant chaque caract\u00e8re\n    par le caract\u00e8re correspondant dans la cle, espace\n    compris. Le texte est en majuscule sans accentuation\n    '''\n    \ndef decodage(texte,cle):\n    '''\n    decode un texte en rempla\u00e7ant chaque caract\u00e8re\n    par le caract\u00e8re correspondant dans la cle, espace\n    compris. Le texte est en majuscule sans accentuation\n    '''\n\n# exercice 3\n\ndef occurence(texte):\n    '''\n    &gt;&gt;&gt;occurence(\"Nsi c'est cool\")\n    {\"N\":1,\"s\":2,\"i\":1,\" \":2.........\"o\":2,\"l\":1}\n    '''\n    \n\ndef frequence(texte):\n    '''\n    &gt;&gt;&gt;\"Nsi c'est cool\"\n    {\"N\":0.0714285714285714..........}\n    '''\n \n\n<\/code><\/pre>\n\n\n\n<p>proposition correction<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Exercice 1\ndossards={1:\"Lovelace\",2:\"Turing\",3:\"Church\"}\ntemps={\"Turing\":53,\"Lovelace\":45,\"Church\":48}\n\ndef fonction1(dossards,temps):\n    '''\n    >>>associe le numero de dossard au temps\n    sous la forme d'un dictionnaire\n    >>>fonction1(dossards,temps)\n    {1:45,2:53,3:48}\n    '''\n    retour={}\n    for numero in dossards:\n       retour&#91;numero]=temps&#91;dossards&#91;numero]]\n    return retour\n    \n# exercice 2\nalphabet=\"ABCDEFGHIJKLMNOPQRSTUVWXYZ \"\nfrom random import *\ndef creation_cle(alphabet):\n    '''\n    associe \u00e0 chaque lettre une et une seule\n    lettre tir\u00e9e au hasard dans l'aphabet donn\u00e9\n    renvoie la reponse sous la forme d'un dictionnaire\n    >>>creation_cle(alphabet)\n    {\"A\":\"Q\",\"B\":\"Z\",.............,\" \":\"E\"}\n    '''\n    alphabet2=alphabet\n    retour={}\n    for caract in alphabet:\n        ind=randint(0,len(alphabet2)-1)\n        val_hasard=alphabet2&#91;ind]\n        alphabet2=alphabet2&#91;:ind]+alphabet2&#91;ind+1:]\n        retour&#91;caract]=val_hasard\n    return retour\n\ncle=creation_cle(alphabet)\n        \n    \ndef codage(texte,cle):\n    '''\n    code un texte en rempla\u00e7ant chaque caract\u00e8re\n    par le caract\u00e8re correspondant dans la cle, espace\n    compris. Le texte est en majuscule sans accentuation\n    '''\n    retour=\"\"\n    for carac in texte:\n        retour+=cle&#91;carac]\n    return retour\n    \ndef decodage(texte,cle):\n    '''\n    decode un texte en rempla\u00e7ant chaque caract\u00e8re\n    par le caract\u00e8re correspondant dans la cle, espace\n    compris. Le texte est en majuscule sans accentuation\n    '''\n    retour=\"\"\n    for car in texte:\n        for c in cle:\n            if cle&#91;c]==car:\n                retour+=c\n    return retour\n    \n    \n# exercice 3\n\ndef occurence(texte):\n    '''\n    >>>occurence(\"Nsi c'est cool\")\n    {\"N\":1,\"s\":2,\"i\":1,\" \":2.........\"o\":2,\"l\":1}\n    '''\n    retour={}\n    for caract in texte:\n        if caract  in retour:\n            retour&#91;caract]+=1\n        else:\n            retour&#91;caract]=1\n    return retour\n    \ndef frequence(texte):\n    '''\n    >>>frequence(\"Nsi c'est cool\")\n    {\"N\":0.0714285714285714..........}\n    '''\n    retour=occurence(texte)\n    for key in retour:\n        retour&#91;key]=retour&#91;key]\/len(texte)\n    return retour\n\n# exo 4\ndef inverse_dico(dict):\n    '''\n    >>>dict={\"A\":3,\"B\":5}\n    >>>inverse_dico(dict)\n    {3:\"A\",5:\"B\"}\n    '''\n    retour={}\n    for cle in dict:\n        retour&#91;dict&#91;cle]]=cle\n    return retour\n<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>proposition correction<\/p>\n","protected":false},"author":2,"featured_media":0,"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\/2940"}],"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=2940"}],"version-history":[{"count":4,"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/posts\/2940\/revisions"}],"predecessor-version":[{"id":2948,"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/posts\/2940\/revisions\/2948"}],"wp:attachment":[{"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/media?parent=2940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/categories?post=2940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labodemaths.fr\/WordPress3\/wp-json\/wp\/v2\/tags?post=2940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}