<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Birendra Kumar on Medium]]></title>
        <description><![CDATA[Stories by Birendra Kumar on Medium]]></description>
        <link>https://medium.com/@birendrakumar_26513?source=rss-ff25ce99b8ce------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*CPxVpeBpkIEf-6vX.</url>
            <title>Stories by Birendra Kumar on Medium</title>
            <link>https://medium.com/@birendrakumar_26513?source=rss-ff25ce99b8ce------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 04:04:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@birendrakumar_26513/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[NamedTuple: Unseen topic in python]]></title>
            <link>https://medium.com/@birendrakumar_26513/namedtuple-unseen-topic-in-python-2b4ffce42ed5?source=rss-ff25ce99b8ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b4ffce42ed5</guid>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Birendra Kumar]]></dc:creator>
            <pubDate>Mon, 22 Jul 2019 14:19:47 GMT</pubDate>
            <atom:updated>2019-07-22T14:19:47.379Z</atom:updated>
            <content:encoded><![CDATA[<p>Python supports a type of container like dictionaries called “namedtuple()” present in module “collection“. Like dictionaries it contain keys that are hashed to a particular value.</p><p>Named tuples are basically easy-to-create, lightweight object types. It’s one of these amazing features in Python that’s hidden in plain sight.</p><p>Let’s take one scenario where user want to process .txt file from a folder or say getting text from from external service in a particular folder. Text file contains Header and contents but it is semi structure file like. e.g:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbd465cd3371f3ee71dc7ba30252cc18/href">https://medium.com/media/cbd465cd3371f3ee71dc7ba30252cc18/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3e77e23c07e486cd8f4c77772b907c3/href">https://medium.com/media/d3e77e23c07e486cd8f4c77772b907c3/href</a></iframe><p>In above code snippet, index place of header name is not static. In first snippet, CompanyName appears in first column but in second snippet it appears in second column.</p><p>How to solve above problem by writing single code which would be valid for different scenario. There can be multiple way to solve this but I find namedtuple offers clean, readable and maintainable code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82a9932e0b9a5fd8b85d2fa7869acc70/href">https://medium.com/media/82a9932e0b9a5fd8b85d2fa7869acc70/href</a></iframe><p>Above code, I am creating a class (line no 25) by using namedtuple function and passing all header name in single string with comma separated. It will define all class property and line no 29, we are initializing a object and pass all value of class properties.</p><p>You can find all code here : <a href="https://github.com/birendra7654/NamedTuple">https://github.com/birendra7654/NamedTuple</a></p><h3>Conclusion:</h3><p>Today, we learned about Python namedtuple. It is just like a regular tuple, apart from the fact that it can also access fields through their names. It is also more memory-efficient than a dictionary</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b4ffce42ed5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>