<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Fila De Prioridade on Python Dev BR</title>
    <link>https://python.dev.br/tags/fila-de-prioridade/</link>
    <description>Recent content in Fila De Prioridade on Python Dev BR</description>
    <generator>Hugo</generator>
    <language>pt-br</language>
    <lastBuildDate>Sun, 23 Aug 2026 06:21:30 +0000</lastBuildDate>
    <atom:link href="https://python.dev.br/tags/fila-de-prioridade/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>heapq em Python: fila de prioridade e top-N na prática</title>
      <link>https://python.dev.br/blog/python-heapq-fila-prioridade/</link>
      <pubDate>Tue, 18 Aug 2026 00:00:00 +0000</pubDate>
      <guid>https://python.dev.br/blog/python-heapq-fila-prioridade/</guid>
      <description>&lt;p&gt;O módulo &lt;code&gt;heapq&lt;/code&gt; é a forma canônica de montar uma &lt;strong&gt;fila de prioridade em Python&lt;/strong&gt; sem instalar nada. Em cima de uma lista comum ele mantém um &lt;em&gt;binary heap&lt;/em&gt;: inserir e remover o menor elemento custam O(log n), e o menor item fica sempre em &lt;code&gt;fila[0]&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;A recomendação direta é: use &lt;code&gt;heappush&lt;/code&gt; / &lt;code&gt;heappop&lt;/code&gt; para agendas, jobs, retries e dijkstra-like; use &lt;code&gt;heapify&lt;/code&gt; quando a lista já existe; use &lt;code&gt;nlargest&lt;/code&gt; / &lt;code&gt;nsmallest&lt;/code&gt; para top-N sem ordenar tudo; e guarde itens como &lt;code&gt;(prioridade, desempate, payload)&lt;/code&gt; para evitar &lt;code&gt;TypeError&lt;/code&gt; em empates. Para a visão estrutural de &lt;a href=&#34;https://python.dev.br/algoritmos/pilhas-filas-python/&#34;&gt;pilhas e filas&lt;/a&gt;, &lt;a href=&#34;https://python.dev.br/blog/collections-python-guia-completo/&#34;&gt;collections&lt;/a&gt; e &lt;a href=&#34;https://python.dev.br/blog/python-threading-threadpoolexecutor/&#34;&gt;threading com Queue&lt;/a&gt;, este guia fecha o buraco do &lt;em&gt;heap&lt;/em&gt; em si.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
