{"id":1160,"date":"2023-02-26T09:22:20","date_gmt":"2023-02-26T08:22:20","guid":{"rendered":"https:\/\/blog.univ-angers.fr\/mathsinfo\/?p=1160"},"modified":"2023-02-26T09:22:20","modified_gmt":"2023-02-26T08:22:20","slug":"recherche-de-mots","status":"publish","type":"post","link":"https:\/\/blog.univ-angers.fr\/mathsinfo\/2023\/02\/26\/recherche-de-mots\/","title":{"rendered":"Recherche de mots"},"content":{"rendered":"\n<p>Suite \u00e0 ma vid\u00e9o d&rsquo;initiation \u00e0 <strong>JavaScript<\/strong> concernant la <span style=\"text-decoration: underline\">recherche de mots<\/span> (palindromes, anacycliques, mots croissants&#8230;), je vous propose ici les traductions en Python<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Initiation \u00e0 JavaScript : Recherche de mots (palindrome, anacyclique...)\" width=\"584\" height=\"329\" src=\"https:\/\/www.youtube.com\/embed\/pMafoGegPIY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Importer les dictionnaires<\/h2>\n\n\n\n<p><a href=\"https:\/\/uabox.univ-angers.fr\/index.php\/s\/nswlHy4HkJEFQgB\" target=\"_blank\" rel=\"noreferrer noopener\">Enregistrez le fichier<\/a> <strong>dicos.py<\/strong> dans un dossier et cr\u00e9ez un fichier <strong>recherche.py<\/strong> dans ce m\u00eame dossier avec pour contenu :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import dicos\n\nprint(len(dicos.dico5))<\/code><\/pre>\n\n\n\n<p>En ex\u00e9cutant le fichier vous devriez voir le nombre <strong>7276<\/strong> qui correspond au nombre de mots de 5 lettres.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Mots en sens inverse et palindromes<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import dicos\n\ndef inverse(mot):\n    return mot&#091;::-1]\n\ndef palindrome(dico):\n    return &#091;mot for mot in dico if mot == inverse(mot)]<\/code><\/pre>\n\n\n\n<p>Testons :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt;&gt; inverse('BONJOUR')\n'RUOJNOB'\n\n&gt;&gt;&gt; palindrome(dicos.dico6)\n&#091;'SASSAS', 'SELLES', 'SENNES', 'SERRES', ... ]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Anacycliques<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>def anacyclique(dico):\n    return &#091;mot for mot in dico if inverse(mot) in dico]<\/code><\/pre>\n\n\n\n<p>Testons :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt;&gt; anacyclique(dicos.dico7)\n&#091;'ALLIACE', 'ALLIAGE', 'ANNOTAT', 'ARETIER',...]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Mots croissants<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>def croissant(dico):\n    return &#091;mot for mot in dico if mot == ''.join(sorted(list(mot)))]<\/code><\/pre>\n\n\n\n<p>Testons :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt;&gt; croissant(dicos.dico6)\n&#091;'ACCENT', 'ACCORT', 'AFFINS', 'AFFLUX', 'AGGLOS', 'BELLOT', 'BIJOUX', 'BILLOT', 'CHINTZ', 'DEHORS', 'EFFORT']<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Q sans U<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>def QsansU(dico):\n    return &#091;mot for mot in dico if 'Q' in mot and 'U' not in mot]<\/code><\/pre>\n\n\n\n<p>Testons :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt;&gt; QsansU(dicos.dico5)\n&#091;'QIBLA']<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Toutes les voyelles<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>def nbVoyelles(mot):\n    return len(&#091;v for v in 'AEIOU' if v in mot])\n\ndef ToutesLesVoyelles(dico):\n    return &#091;mot for mot in dico if nbVoyelles(mot) == 5]<\/code><\/pre>\n\n\n\n<p>Testons :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt;&gt; nbVoyelles('BONJOUR')\n2\n\n&gt;&gt;&gt; ToutesLesVoyelles(dicos.dico6)\n&#091;'EBOUAI', 'ENOUAI', 'OISEAU']<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Suite \u00e0 ma vid\u00e9o d&rsquo;initiation \u00e0 JavaScript concernant la recherche de mots (palindromes, anacycliques, mots croissants&#8230;), je vous propose ici les traductions en Python Importer les dictionnaires Enregistrez le fichier dicos.py dans un dossier et cr\u00e9ez un fichier recherche.py dans &hellip; <a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/2023\/02\/26\/recherche-de-mots\/\">Continuer la lecture <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":4913,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1160","post","type-post","status-publish","format-standard","hentry","category-non-classe"],"_links":{"self":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts\/1160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/users\/4913"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/comments?post=1160"}],"version-history":[{"count":1,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts\/1160\/revisions"}],"predecessor-version":[{"id":1161,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts\/1160\/revisions\/1161"}],"wp:attachment":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/media?parent=1160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/categories?post=1160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/tags?post=1160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}