<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Collection | Haobin Tan</title><link>https://haobin-tan.netlify.app/tags/collection/</link><atom:link href="https://haobin-tan.netlify.app/tags/collection/index.xml" rel="self" type="application/rss+xml"/><description>Collection</description><generator>Hugo Blox Builder (https://hugoblox.com)</generator><language>en-us</language><lastBuildDate>Sun, 01 May 2022 00:00:00 +0000</lastBuildDate><image><url>https://haobin-tan.netlify.app/media/icon_hu7d15bc7db65c8eaf7a4f66f5447d0b42_15095_512x512_fill_lanczos_center_3.png</url><title>Collection</title><link>https://haobin-tan.netlify.app/tags/collection/</link></image><item><title>Data Structures and Collections</title><link>https://haobin-tan.netlify.app/docs/coding/python/data-structures-and-collections/</link><pubDate>Sun, 01 May 2022 00:00:00 +0000</pubDate><guid>https://haobin-tan.netlify.app/docs/coding/python/data-structures-and-collections/</guid><description/></item><item><title>Namedtuple</title><link>https://haobin-tan.netlify.app/docs/coding/python/data-structures-and-collections/namedtuple/</link><pubDate>Sat, 02 May 2020 00:00:00 +0000</pubDate><guid>https://haobin-tan.netlify.app/docs/coding/python/data-structures-and-collections/namedtuple/</guid><description>&lt;p>&lt;strong>TL;DR&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;code>collection.namedtuple&lt;/code> is a memory-efficient shortcut to defining an immutable class in Python manually.&lt;/li>
&lt;li>Namedtuples can help clean up your code by enforcing an easier to understand structure on your data, which also improves readability.&lt;/li>
&lt;li>Namedtuples provide a few useful helper methods that all start with an &lt;code>_&lt;/code> underscore—but are part of the public interface.&lt;/li>
&lt;/ul>
&lt;h2 id="what-is-namedtuple">What is &lt;code>namedtuple&lt;/code>?&lt;/h2>
&lt;p>Python’s tuple is a simple immutable data structure for grouping arbitrary objects. It has two shortcomings:&lt;/p>
&lt;ul>
&lt;li>The data you store in it can only be pulled out by accessing it through integer indexes. You can’t give names to individual properties stored in a tuple. This can impact code readability.&lt;/li>
&lt;li>It’s hard to ensure that two tuples have the same number of fields and the same properties stored on them.&lt;/li>
&lt;/ul>
&lt;p>&lt;code>namedtuple&lt;/code> aims to solve these two problems. &lt;a href="http://docs.python.org/2/library/collections.html#collections.namedtuple">namedtuple&lt;/a> is a &lt;strong>factory function&lt;/strong> for making a tuple class. With that class we can create tuples that are callable by name also.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;code>namedtuple&lt;/code> is &lt;em>immutable&lt;/em> just like regular tuple&lt;/p>
&lt;ul>
&lt;li>Once you store data in top-level attribute on a namedtuple, you can’t modify it by updating the attribute.&lt;/li>
&lt;li>All attributes on a namedtuple object follow the &lt;strong>“write once, read many” principle&lt;/strong>.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>Each object stored in them can be accessed through a unique (human-readable) string identifier.&lt;/p>
&lt;p>→ This frees you from having to remember integer indexes, or resorting to workarounds like defining integer constants as mnemonics for your indexes. 👏&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="how-namedtuple-works">How &lt;code>namedtuple&lt;/code> works?&lt;/h2>
&lt;p>Let&amp;rsquo;s take a look at an example:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">collections&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">namedtuple&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">User&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">namedtuple&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;User&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;gender&amp;#34;&lt;/span>&lt;span class="p">])&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">user&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">User&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;Ecko&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;male&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="o">&amp;gt;&amp;gt;&amp;gt;&lt;/span> &lt;span class="n">user&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">User&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;Ecko&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nb">id&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">gender&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;male&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>&lt;code>&amp;quot;User&amp;quot;&lt;/code> as the first argument to the &lt;code>namedtuple &lt;/code>factory function is referred to as the “typename” in the Python docs. It’s the name of the new class that’s being created by calling the &lt;code>namedtuple &lt;/code>function, which needs to be &lt;em>explicitly&lt;/em> specified.&lt;/li>
&lt;/ul>
&lt;p>The code above is equivalent to&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">User&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="fm">__init__&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nb">id&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">gender&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">name&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">name&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">id&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="nb">id&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">gender&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">gender&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">user&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">User&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;Ecko&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;male&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="why-namedtuple">Why &lt;code>namedtuple&lt;/code>?&lt;/h2>
&lt;p>Namedtuple objects are implemented as regular Python classes internally. &lt;span style="color: ForestGreen">When it comes to memory usage, they are also “better” than regular classes and just as memory efficient as regular tuples. 👍&lt;/span>&lt;/p>
&lt;p>A good way to view them is to think that &lt;em>&lt;strong>namedtuples are a memory-efficient shortcut to defining an immutable class in Python manually&lt;/strong>&lt;/em>.&lt;/p>
&lt;h2 id="operations">Operations&lt;/h2>
&lt;h3 id="unpacking">Unpacking&lt;/h3>
&lt;p>Tuple unpacking and the &lt;code>*&lt;/code>-operator for function argument unpacking also work as expected:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nb">id&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">gender&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">user&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;name: &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">, id: &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="nb">id&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">, gender: &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">gender&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-txt" data-lang="txt">&lt;span class="line">&lt;span class="cl">name: Ecko, id: 1, gender: male
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-txt" data-lang="txt">&lt;span class="line">&lt;span class="cl">Ecko 1 male
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="accessing-values">Accessing Values&lt;/h3>
&lt;p>Values can be accessed either by identifier or by index.&lt;/p>
&lt;p>By identifier:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="o">&amp;gt;&amp;gt;&amp;gt;&lt;/span> &lt;span class="n">user&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">name&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">Ecko&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>By index:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="o">&amp;gt;&amp;gt;&amp;gt;&lt;/span> &lt;span class="n">user&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="mi">0&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">Ecko&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="built-in-helper-functions">Built-in Helper Functions&lt;/h3>
&lt;p>&lt;code>namedtuple&lt;/code> has some useful helper methods.&lt;/p>
&lt;ul>
&lt;li>Their names all start with an underscore character &lt;code>_&lt;/code>
&lt;ul>
&lt;li>With &lt;code>namedtuples&lt;/code> the underscore naming convention has a different meaning though: These helper methods and properties are part of namedtuple’s public interface.&lt;/li>
&lt;li>The helpers were named that way to avoid naming collisions with user-defined tuple fields.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h4 id="_asdict">&lt;code>_asdict&lt;/code>&lt;/h4>
&lt;p>Returns the contents of a &lt;code>namedtuple &lt;/code>as a dictionary&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="o">&amp;gt;&amp;gt;&amp;gt;&lt;/span> &lt;span class="n">user&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">_asdict&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">OrderedDict&lt;/span>&lt;span class="p">([(&lt;/span>&lt;span class="s1">&amp;#39;name&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;Ecko&amp;#39;&lt;/span>&lt;span class="p">),&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;id&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">),&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;gender&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;male&amp;#39;&lt;/span>&lt;span class="p">)])&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This is great for avoiding typos in the field names when generating JSON-output, for example:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="o">&amp;gt;&amp;gt;&amp;gt;&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="nn">json&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">&amp;gt;&amp;gt;&amp;gt;&lt;/span> &lt;span class="n">json&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">dumps&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">_asdict&lt;/span>&lt;span class="p">())&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s1">&amp;#39;{&amp;#34;name&amp;#34;: &amp;#34;Ecko&amp;#34;, &amp;#34;id&amp;#34;: 1, &amp;#34;gender&amp;#34;: &amp;#34;male&amp;#34;}&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>We can convert a dictionary into a &lt;code>namedtuple&lt;/code> with &lt;code>**&lt;/code> operator&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="o">&amp;gt;&amp;gt;&amp;gt;&lt;/span> &lt;span class="n">user_dict&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="s2">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Ben&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;gender&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;male&amp;#34;&lt;/span>&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">&amp;gt;&amp;gt;&amp;gt;&lt;/span> &lt;span class="n">User&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="n">user_dict&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">User&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;Ben&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nb">id&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">gender&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;male&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="_replace">&lt;code>_replace()&lt;/code>&lt;/h4>
&lt;p>Creates a (shallow) copy of a tuple and allows you to selectively replace some of its fields.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">user&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">_replace&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nb">id&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-txt" data-lang="txt">&lt;span class="line">&lt;span class="cl">User(name=&amp;#39;Ecko&amp;#39;, id=2, gender=&amp;#39;male&amp;#39;)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="_make">&lt;code>_make()&lt;/code>&lt;/h4>
&lt;p>Classmethod can be used to create new instances of a namedtuple from a sequence or iterable&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">User&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">_make&lt;/span>&lt;span class="p">([&lt;/span>&lt;span class="s2">&amp;#34;Ilona&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="mi">3&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;female&amp;#34;&lt;/span>&lt;span class="p">])&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-txt" data-lang="txt">&lt;span class="line">&lt;span class="cl">User(name=&amp;#39;Ilona&amp;#39;, id=3, gender=&amp;#39;female&amp;#39;)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="when-to-use-namedtuple">When to Use &lt;code>namedtuple&lt;/code>?&lt;/h2>
&lt;ul>
&lt;li>If you&amp;rsquo;re going to create a bunch of instances of a class and NOT change the attributes after you set them in &lt;code>__init__&lt;/code>, you can consider to use &lt;code>namedtuple&lt;/code>.
&lt;ul>
&lt;li>Example: Definition of classes in &lt;a href="https://pytorch.org/vision/stable/_modules/torchvision/datasets/cityscapes.html">&lt;code>torchvision.datasets.cityscapes&lt;/code>&lt;/a>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Namedtuples can be an easy way to clean up your code and to make it more readable by enforcing a better structure for your data. You should use &lt;code>namedtuple&lt;/code> &lt;strong>anywhere you think object notation will make your code more pythonic and more easily readable&lt;/strong>&lt;/li>
&lt;li>But try NOT to use namedtuples for their own sake if they don’t help you write “cleaner” and more maintainable code.&lt;/li>
&lt;/ul>
&lt;h2 id="reference">Reference&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>&lt;a href="https://dbader.org/blog/writing-clean-python-with-namedtuples">Writing Clean Python With Namedtuples&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://stackoverflow.com/questions/9872255/when-and-why-should-i-use-a-namedtuple-instead-of-a-dictionary">When and why should I use a namedtuple instead of a dictionary?&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://stackoverflow.com/questions/2970608/what-are-named-tuples-in-python">What are “named tuples” in Python?&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://blog.csdn.net/zV3e189oS5c0tSknrBCL/article/details/78496429">什么时候使用 namedtuple&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://www.geeksforgeeks.org/namedtuple-in-python/">Namedtuple in Python&lt;/a>&lt;/p>
&lt;/li>
&lt;/ul></description></item></channel></rss>