<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jaako</title>
    <description>The latest articles on DEV Community by Jaako (@jaakofalltrade).</description>
    <link>https://dev.to/jaakofalltrade</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F275624%2Fc9b05cbf-c360-41a1-b447-2dc4fcc1bac0.jpeg</url>
      <title>DEV Community: Jaako</title>
      <link>https://dev.to/jaakofalltrade</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jaakofalltrade"/>
    <language>en</language>
    <item>
      <title>Virtualenv(pipenv) in Docker?</title>
      <dc:creator>Jaako</dc:creator>
      <pubDate>Tue, 21 Jan 2020 09:37:01 +0000</pubDate>
      <link>https://dev.to/jaakofalltrade/virtualenv-pipenv-in-docker-3993</link>
      <guid>https://dev.to/jaakofalltrade/virtualenv-pipenv-in-docker-3993</guid>
      <description>&lt;h1&gt;
  
  
  Is it necessary to use Virtualenv in Docker?
&lt;/h1&gt;

&lt;p&gt;I am currently developing a fullstack project using &lt;em&gt;Django Restframework&lt;/em&gt; and &lt;em&gt;React&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;I have already made a working &lt;strong&gt;Dockerfile&lt;/strong&gt; and a &lt;strong&gt;docker-compose.yml&lt;/strong&gt; for both &lt;em&gt;React&lt;/em&gt; and &lt;em&gt;Django&lt;/em&gt; but none of my colleagues are using &lt;strong&gt;Docker&lt;/strong&gt; instead they are only using &lt;em&gt;pipenv&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I am thinking of implementing &lt;strong&gt;pipenv&lt;/strong&gt; inside a &lt;strong&gt;Docker&lt;/strong&gt; but is it necessary? and also which one is the best?&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank you...
&lt;/h2&gt;

</description>
      <category>help</category>
      <category>python</category>
      <category>docker</category>
    </item>
    <item>
      <title>Python tips for beginners, the inexperienced, the beaten and the damned...</title>
      <dc:creator>Jaako</dc:creator>
      <pubDate>Wed, 18 Dec 2019 08:51:03 +0000</pubDate>
      <link>https://dev.to/jaakofalltrade/python-tips-for-beginners-the-inexperienced-the-beaten-and-the-damned-4310</link>
      <guid>https://dev.to/jaakofalltrade/python-tips-for-beginners-the-inexperienced-the-beaten-and-the-damned-4310</guid>
      <description>&lt;h2&gt;
  
  
  What I think about Python?
&lt;/h2&gt;

&lt;p&gt;I learned how to code in Python when I was just a sophomore college student, and for a student who only knows how to code in C and have only seen low-level programming languages like Fortran, Basic and Cobol. Discovering Python was a Godsend.&lt;/p&gt;

&lt;p&gt;I can never forget that feeling of witnessing a 15 liner in C reduced to a 1 liner in Python. It felt magical, the same feeling as a mathematician discovering a new formula for the first time. Just pure amazement of the things it could do.&lt;/p&gt;

&lt;p&gt;And if I'm going to rate Python from 1 to 10 it would be the cover photo above.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's start!
&lt;/h2&gt;

&lt;p&gt;These are for beginners, the inexperienced and those who have just started learning Python.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. First tip! Follow and Conform to the PEP 8 style guide
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/CXcKi9NsRYa8U/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/CXcKi9NsRYa8U/giphy.gif" alt="Conform"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Most beginners do not even follow the &lt;strong&gt;PEP 8 style guide&lt;/strong&gt; nor even have heard about it.&lt;/p&gt;

&lt;p&gt;When I started coding in Python, I did not follow any style guides whatsoever. I only did the bare minimum and as much as possible I try to &lt;em&gt;make the code not confusing&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In fact, I have only heard about PEP 8 and other style guides just recently upon entering the coding industry, what a shame.&lt;/p&gt;

&lt;p&gt;I'm not going to explain PEP 8 or its pros and cons in this post, so here are some links that could help you learn more about it.&lt;/p&gt;

&lt;p&gt;My favorite link to learn PEP 8: &lt;a href="https://realpython.com/python-pep8/"&gt;https://realpython.com/python-pep8/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another link where I got this awesome quote from: &lt;a href="https://www.python.org/dev/peps/pep-0008/"&gt;https://www.python.org/dev/peps/pep-0008/&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;However, know when to be inconsistent -- sometimes style guide recommendations just aren't applicable. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And there is also a PEP 8 checker: &lt;a href="http://pep8online.com/"&gt;http://pep8online.com/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Second tip! Don't use list comprehension other than making a list.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/spfi6nabVuq5y/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/spfi6nabVuq5y/giphy.gif" alt="No way"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another thing that I see most beginners do is their blatant use of list comprehensions. I'm also not a stranger to that mistake, and I am very thankful that an experienced programmer told me how to properly use it.&lt;/p&gt;

&lt;p&gt;Comprehensions are supposed to return a list, dictionary a set or a generator and using it other than that beats its purpose.&lt;/p&gt;

&lt;p&gt;Using list comprehensions to print some values is forgivable but appending values to other list, that is heresy of the highest order. &lt;/p&gt;

&lt;p&gt;I mean you can get a free pass to use comprehensions when you're debugging something just make sure you remove it afterwards. But anything other than that is a big &lt;strong&gt;NO&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is forgivable,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s"&gt;'I love number &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;!'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;because you only shortened this code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s"&gt;'I love number &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;!'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But this on the other hand is heresy,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://i.giphy.com/media/vtPiQBn0wwXo4/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/vtPiQBn0wwXo4/giphy.gif" alt="deus vult"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and can be easily refactored to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One might argue, &lt;em&gt;"But it is a lot shorter and cleaner sire..."&lt;/em&gt;. Well, you are not wrong but comprehensions are created for another purpose my child.&lt;/p&gt;

&lt;p&gt;It's just the same as saying that &lt;em&gt;"Killing all of the world's population could save the planet"&lt;/em&gt;. It might be the right thing to do but why are we saving the planet in the first place? or saying that &lt;em&gt;"A knife can be used as a spoon also"&lt;/em&gt;. Yes, you can use it as a spoon but a knife is not made for that kind of function and you'll just hurt yourself in doing so.&lt;/p&gt;

&lt;h4&gt;
  
  
  Bonus tip:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;There are people who don't know the difference between a &lt;strong&gt;list&lt;/strong&gt; and a &lt;strong&gt;generator&lt;/strong&gt;, and when to use them. Make sure to be in the know.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can read more about &lt;strong&gt;list&lt;/strong&gt; vs &lt;strong&gt;generators&lt;/strong&gt; here: &lt;a href="https://code-maven.com/list-comprehension-vs-generator-expression"&gt;https://code-maven.com/list-comprehension-vs-generator-expression&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Third tip! Utilize f-strings!
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/J2OIhU2JZKO3ZAyAUF/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/J2OIhU2JZKO3ZAyAUF/giphy.gif" alt="reason"&gt;&lt;/a&gt;&lt;br&gt;
For some reason other programmers are not utilizing this radical way of formatting a string. It's a lot faster, better and less prone to error so why aren't everyone using it?&lt;/p&gt;
&lt;h4&gt;
  
  
  Check the code below for comparison:
&lt;/h4&gt;

&lt;p&gt;Ugly and not elegant.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="c1"&gt;# Stop doing this
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The tree is "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" years old."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is not sexy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Prone to error
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The tree is %s years old."&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even more so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# This has a tendency to become extremely long.
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The tree is {} years old."&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the real deal and sexy as hell.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# A lot faster and less prone to error
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s"&gt;"The tree is &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; years old."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm not going to dive deep about why f-string is the future, so here are some links for you to read and learn more.&lt;/p&gt;

&lt;p&gt;Explains why you need to use f-string:&lt;br&gt;
&lt;a href="https://realpython.com/python-f-strings/"&gt;https://realpython.com/python-f-strings/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How they work:&lt;br&gt;
&lt;a href="https://hackernoon.com/a-closer-look-at-how-python-f-strings-work-f197736b3bdb"&gt;https://hackernoon.com/a-closer-look-at-how-python-f-strings-work-f197736b3bdb&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;String formatting best practices:&lt;br&gt;
&lt;a href="https://realpython.com/python-string-formatting/"&gt;https://realpython.com/python-string-formatting/&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  4. Fourth tip, Use the Python modules and utilize every one of them.
&lt;/h3&gt;

&lt;p&gt;Whether it is a builtin module or a package which you need to install, you need to learn how to utilize them properly.&lt;/p&gt;

&lt;p&gt;This is another thing that most inexperienced Python programmers overlook. They tend to not use any of the modules that could help make their jobs a lot easier.&lt;/p&gt;
&lt;h4&gt;
  
  
  When you are not utilizing those modules.
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/FCerKwnJpUqnm/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/FCerKwnJpUqnm/giphy.gif" alt="notutilized"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  When you are utilizing those modules.
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/6e61n9Z25XOGk/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/6e61n9Z25XOGk/giphy.gif" alt="utilized"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All you need to do is read and understand the documentation.&lt;/p&gt;

&lt;p&gt;I learned that just because everything is working fine does not mean it cannot be improved. Using a module could make your code more efficient and faster. It can also reduce the lines dramatically by removing unnecessary codes that the module replaced. &lt;/p&gt;
&lt;h4&gt;
  
  
  For example, we want to count how many of each color appeared in the list.
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'green'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'red'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'red'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'green'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'green'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'red'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'orange'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'green'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'green'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'green'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'red'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We could do this, which is U-G-L-Y ugly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But can be improved to this, by utilizing dictionary comprehension and it looks meh:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But by using Counter from collections module, tada! I now present a lot cleaner and shorter code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;collections&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Counter&lt;/span&gt;

&lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Here are some useful modules:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/library/datetime.html"&gt;datetime&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/library/itertools.html"&gt;itertools&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/library/functools.html"&gt;functools&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/library/collections.html"&gt;collections&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://3.python-requests.org/"&gt;requests&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/library/sqlite3.html"&gt;sqlite3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arrow.readthedocs.io/en/latest/"&gt;arrow&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  That's all folks!
&lt;/h2&gt;

&lt;p&gt;To be honest this post is a lot more about my mistakes as a beginner and what I learned from it. I hope that you learned from this post and always get feedback from anyone that you think could help you improve your skills as a programmer.&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
