<?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 Tuan le Van on Medium]]></title>
        <description><![CDATA[Stories by Tuan le Van on Medium]]></description>
        <link>https://medium.com/@tuanlevan?source=rss-b3a15a019da9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7FRorWRinFRITMJz.</url>
            <title>Stories by Tuan le Van on Medium</title>
            <link>https://medium.com/@tuanlevan?source=rss-b3a15a019da9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 16:11:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tuanlevan/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[Better coding in Python]]></title>
            <link>https://medium.com/@tuanlevan/better-coding-in-python-8a0ef7bdba06?source=rss-b3a15a019da9------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a0ef7bdba06</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Tuan le Van]]></dc:creator>
            <pubDate>Wed, 14 Oct 2020 01:07:30 GMT</pubDate>
            <atom:updated>2020-10-14T01:07:30.179Z</atom:updated>
            <content:encoded><![CDATA[<p>Here is some tips and tricks for writing better code in Python</p><h3>Tuple</h3><h4>tuple unpacking</h4><p>parallel assignment of tuple in python is readable and flexible</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b04ff8176319e039c33ee0869f197c64/href">https://medium.com/media/b04ff8176319e039c33ee0869f197c64/href</a></iframe><p>using dummy variable</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7dbcb4375802e753abecf29ed490ea50/href">https://medium.com/media/7dbcb4375802e753abecf29ed490ea50/href</a></iframe><p>grab excess items</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90e180867bc37d0b5a091275cfc1e3f9/href">https://medium.com/media/90e180867bc37d0b5a091275cfc1e3f9/href</a></iframe><p>nested tuple unpacking</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c00de319307b78e315f9268c252cc342/href">https://medium.com/media/c00de319307b78e315f9268c252cc342/href</a></iframe><h4>Named tuples</h4><p>collection.namedtuple is factory function for creating tuple subclasses with named fields. The instance take exactly the same amount of memory as tuple. Named tuple assign are readable and self-documenting code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5602634bba6dbc4d66b3fc75bf6e8f48/href">https://medium.com/media/5602634bba6dbc4d66b3fc75bf6e8f48/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6040f741bba44d4212178e476c456191/href">https://medium.com/media/6040f741bba44d4212178e476c456191/href</a></iframe><p>We can be more explicit with NamedTuple (python3)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23b1e0c02fac25b8586438bc97715d82/href">https://medium.com/media/23b1e0c02fac25b8586438bc97715d82/href</a></iframe><h3>String Manipulation</h3><h4>remove some leading and trailing characters</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/136de69ad92023be0e68a770928e34ba/href">https://medium.com/media/136de69ad92023be0e68a770928e34ba/href</a></iframe><h4>separate string</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0208e587168aadee64beab8862db441a/href">https://medium.com/media/0208e587168aadee64beab8862db441a/href</a></iframe><h4>align string</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2bc11e068fbada3aa8fb4eb748ca1f4/href">https://medium.com/media/f2bc11e068fbada3aa8fb4eb748ca1f4/href</a></iframe><h3>Item and Attribute Accessing</h3><h4>get value for a key in dictionnary</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba391e390c57cdb12009d35d4ae38e92/href">https://medium.com/media/ba391e390c57cdb12009d35d4ae38e92/href</a></iframe><h4>clean code with slice objects</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1035266363bc3b8db1118a77ccf78908/href">https://medium.com/media/1035266363bc3b8db1118a77ccf78908/href</a></iframe><h4><strong>clean code with itemgetter</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/447977198ef455a84267c4269b8a97f5/href">https://medium.com/media/447977198ef455a84267c4269b8a97f5/href</a></iframe><h4>clean code with attrgetter</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a79ffbe361215a634a3229214c7234c/href">https://medium.com/media/3a79ffbe361215a634a3229214c7234c/href</a></iframe><h3>Dictionnary</h3><h4>use defaultdict</h4><p>get indexes of all occurrences of character in a string</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7e12f8f203a0462d83b3fe8fcfee043/href">https://medium.com/media/c7e12f8f203a0462d83b3fe8fcfee043/href</a></iframe><h4>maintain insertion order</h4><p>from python3.6, the standard dict maintains insertion order. For previous version, we can use OrderedDict.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0da406e6a40380c3742069078ee4dd5/href">https://medium.com/media/c0da406e6a40380c3742069078ee4dd5/href</a></iframe><h4>remove duplicates from a list while preserving order (in py2 and py3)</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cd4689fa0a96ddb01e77d3e5e5d0ba2/href">https://medium.com/media/6cd4689fa0a96ddb01e77d3e5e5d0ba2/href</a></iframe><h3>Function</h3><h4>use function as object</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51e1c7372e29133f77d049efcefdcda5/href">https://medium.com/media/51e1c7372e29133f77d049efcefdcda5/href</a></iframe><h4>function instead of class</h4><p>sometimes, instead of defining and instantiating classes, you can simply use functions.</p><blockquote><strong>nonlocal </strong>declaration was introduced in python 3 to make a function inside a function, which uses the variable as a non local variable</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04ab6a62401df59319339194cddadbbb/href">https://medium.com/media/04ab6a62401df59319339194cddadbbb/href</a></iframe><p>Most of the tricks and tips i have learned from <a href="https://www.amazon.fr/dp/B0131L3PW4/"><strong>Fluent Python </strong>by Luciano Ramalho</a> and from my current job.</p><p>Thank you for reading and I hope you found this article helpul!</p><p>If you have any suggestions please don’t hesitate to comment. 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a0ef7bdba06" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>