<?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 Erik Batista on Medium]]></title>
        <description><![CDATA[Stories by Erik Batista on Medium]]></description>
        <link>https://medium.com/@erikbatista42?source=rss-3f884d4a30a2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_Q_hSVzRk-cs6ekj_uJWPA.png</url>
            <title>Stories by Erik Batista on Medium</title>
            <link>https://medium.com/@erikbatista42?source=rss-3f884d4a30a2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 19:21:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@erikbatista42/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[Introduction to Refactoring with Python]]></title>
            <link>https://medium.com/@erikbatista42/introduction-to-refactoring-with-python-2cee94304b7b?source=rss-3f884d4a30a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cee94304b7b</guid>
            <dc:creator><![CDATA[Erik Batista]]></dc:creator>
            <pubDate>Thu, 14 May 2020 03:39:09 GMT</pubDate>
            <atom:updated>2020-05-14T03:39:09.598Z</atom:updated>
            <content:encoded><![CDATA[<p>What is it? Why is it good? How do we do it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bb96SLaNJJKnAXS2.jpg" /><figcaption>From messy to clean</figcaption></figure><p>Ever wonder how you In this article, we’ll go over the basics of refactoring. We’ll learn little tips and tricks, the importance of refactoring, and when to use it.</p><h3><strong>What is Refactoring?</strong></h3><p>Refactoring is when you clean your code. Clean code contains some if not all of these components:</p><ul><li>Good variable naming</li><li>Minimal number of classes, methods and moving parts</li><li>No duplication</li><li>Easier to maintain</li><li>Using the programming language’s conventions</li><li>Comments/Documentation if needed</li></ul><h3>What’s the purpose of it?</h3><p>One of the main reasons you refactor is to have readable code. You can understand all the code when you’re coding but if you do come back a few months later and your variable names don’t make sense or there’s duplication happening, or no comments in your code, there’s a high chance you’ll have some trouble reading it. Another purpose of refactoring is for future developers that read your code. This is why it’s important to have comments in your code.</p><h3>When is it the right time to do it?</h3><ul><li>When you’re trying to fix a bug in someone else’s code — If you see they need refactoring, it’s a good opportunity to learn even better how their code works and while refactoring, you might find the bug you’re trying to fix.</li><li>When you submit it for a code review — You might wanna clean your code up a bit before the code becomes available to the public. Submitting a refactored code review is great because another person might add some things to it that would make it easier to read/understand.</li><li>When you see yourself repeating code for a second or third time.</li></ul><h3><strong>Code Smell</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*5isRXxoj4Yoq4ilR.jpg" /><figcaption>Arrow Code</figcaption></figure><p>Sometimes you can look at code and without reading everything, you can tell you’re in for a bad time in a few seconds. This is called code smell. If you or someone has nested if-and-else statements in their code like the picture above, you can already smell the code without reading everything. This type of code is called <strong>arrow code </strong>(When you have nested if-and-else statements or for/while loops). And if you spot arrow code at first glance, your code will smell bad and somebody will already know what they’re getting themselves into within a few seconds. But there are many ways</p><h3>How to Refactor</h3><p>When you refactor, there are a few things you should keep in mind:</p><ul><li>New functionality shouldn’t be added when refactoring — Refactoring should be focused on writing clean understandable code. Try to add new functionality/features separate from cleaning your code.</li><li>At the end of refactoring, your code should be cleaner — If, at the end of refactoring your code is still messy or hasn’t improved, you might have wasted some time.</li><li>If your code smells bad</li></ul><p>Welp! That’s all for now 🙂 If you liked this post, make sure to give it a clap and share 👏. If you have any feedback or additional comments, comment below!</p><h3>Resources</h3><p>Here are the resources I used to put this article together. I would recommend going through these if you want to go more in-depth about refactoring.</p><ol><li><a href="https://apiumhub.com/tech-blog-barcelona/code-smells/">Code Smells</a>, Apiumhub</li><li><a href="https://refactoring.guru/refactoring/what-is-refactoring">What is Refactoring</a>, Refactoring Guru</li><li><a href="https://en.wikipedia.org/wiki/Code_refactoring">Code Refactoring</a>, Wikipedia</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cee94304b7b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An introduction to hash tables with Python]]></title>
            <link>https://medium.com/@erikbatista42/an-introduction-to-hash-tables-with-python-817772cad688?source=rss-3f884d4a30a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/817772cad688</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[hash-table]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[maps]]></category>
            <dc:creator><![CDATA[Erik Batista]]></dc:creator>
            <pubDate>Fri, 06 Mar 2020 06:03:46 GMT</pubDate>
            <atom:updated>2022-03-29T02:13:37.886Z</atom:updated>
            <content:encoded><![CDATA[<h3>An Introduction to Hash Tables With Python</h3><h4>What is it? What is it good for? And how do they work?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*BgbhTUpH4BEA_TKw" /><figcaption>Picture by: <a href="https://unsplash.com/@johnschno">John Schnobrich</a></figcaption></figure><p>Before we get into this article, you should know that I will be having some code samples and to get a good sense of each line of code, you should look at this <a href="https://github.com/erikbatista42/CS-1.3-Core-Data-Structures/blob/master/Code/hashtable.py">hash table class</a> that I made. I won’t be reviewing the code line by line or method by method but you’ll get a good sense of what the code and concept would look like if you have the <a href="https://github.com/erikbatista42/CS-1.3-Core-Data-Structures/blob/master/Code/hashtable.py">hash table class</a> as a reference.</p><h3><strong>Distinguishing Dictionaries and Hash Tables</strong></h3><h4><strong>What a Dictionary is</strong></h4><p>Before we jump into hash tables, it’s a good idea to define a dictionary first. Just like a real-life dictionary where a word maps to a definition, in Computer Science a dictionary is a <strong>general concept that maps keys to values.</strong></p><h4><strong>Isn’t a hash table and dictionary the same thing?</strong></h4><p>You might have heard people used these two words interchangeably. However, now that we know that a dictionary is a general concept that maps keys to values… isn’t a hash table the same thing? Nope, it’s not!</p><h4><strong>What a hash table is</strong></h4><p>A hash table is a <strong>specific way</strong> to implement a dictionary. There are other ways of implementing a dictionary. Another way includes <a href="https://en.wikipedia.org/wiki/Red-black_tree">red-black trees</a>.</p><h4><strong>Putting Hash Tables and Dictionaries together</strong></h4><p>In Python, dictionaries are implemented as Hash Tables. Below is an image for a better understanding of what you just read:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/0*cixKWFuCza2bcWha" /><figcaption>A visual representation of a hash table</figcaption></figure><h4><strong>How Hash Tables work</strong></h4><p>We’re going to understand how most hash tables work. In Python, there are things that are implemented differently than most languages which I will go over again later in this article. Knowing this way of how a hash table works, is the most useful since this is how most languages have their hash tables built under the hood.</p><p>The key and value in a dictionary can be any data type. Most of the time, the key is a string. However, the key and value could be a string, integer, person, circle, pretty much anything…as long as you have a <strong>hash function </strong>(We will discuss this soon).</p><h4><strong>Necessary ingredients that a hash table needs</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HH9PMCiQ3aTk2fLz" /><figcaption>A hamburger with sauces representing a hashtable</figcaption></figure><h4><strong>An Array of buckets</strong></h4><p>We need an array to store items. Each item consists of a bucket. Each bucket is a Singly Linked List.</p><h4><strong>Hash Function</strong></h4><p>A hash function takes in a string, converts that string into some sort of integer(this integer is called the hash code), and then remaps the hash code into an index(item in the index is a “bucket”) in the array. The goal of a hash function in a hash table is to return the index of where we want to put the key-value pair entry. There are different types of hash functions but for this example, we are going to say that our hash function is defined as below:</p><pre><em>def</em> _bucket_index(<em>self</em>, <em>key</em>):</pre><pre>“””Return the bucket index where the given key would be stored.”””</pre><pre>    return hash(key) % len(<em>self</em>.buckets)</pre><p>The code above simply takes in the key(a string in our case) and then when hashing the key (hash(key)). <strong>This becomes our hash code </strong>and we call the modulus operator on the number of buckets we currently have. Like I said earlier, this is a very simple hash function. Hash functions that are built-in languages are usually more robust and perform differently from the code above.</p><h4><strong>Linked Lists</strong></h4><p>Okay, so we used the hash function and using the integer it outputs, which is an index. The index is where the “bucket” or linked list is…and when we access the array by that index or <em>bucket</em>, our bucket is a singly linked list where we are going to store our key-value pair entry.</p><h4><strong>Hash Collision</strong></h4><p>What if you are adding multiple key-value pairs into the hash table and we happen to encounter the same index / linked list of a key-value pair we entered before? This is known as a <strong>hash collision. </strong>One way to handle this is by using a linked list. By using a singly linked linked list, this method of a hash collision is called <strong>“chaining”.</strong> What chaining means is “Hey, if there are any collisions, store them in a linked list”. Since we are using a linked list, we are able to store multiple entries. You are not limited to linked lists. You can also handle hash collisions with other data structures such as trees.</p><h4><strong>Load factor</strong></h4><p>We’ve added enough entries to the point where some of our linked lists are very long. Therefore, it’s sometimes taking a while to retrieve the value of the key we are looking for. In a hash table, a<strong> load factor is a number that measures how full the hash table is. </strong>If our load factor is 0.75, when the load factor reaches above 0.75, the hash table will call the <em>resize operation.</em> This way, we are able to keep the hash table efficient.</p><h4><em>Formula of load factor:</em></h4><p><em>L= number of entries/number of buckets</em></p><h4><strong>Hash Table Resizing</strong></h4><p>Now we know that the hash table calls the resize operation when the load factor exceeds a certain number. Let’s see how the resizing operation works.</p><h4><strong>The set method in the hash table</strong></h4><p>Within the hash table, there is a method called “set” or something related which all it does is add a key-value entry.</p><h3><strong>There are 3 things you could do in order to resize your hash table:</strong></h3><p><strong>1 — Get a list of all key-value entries</strong></p><pre>temp_entries = []</pre><pre>for entry in self.entries:</pre><pre>      temp_entries.append(entry)</pre><h4>2 — Re-initialize the array of buckets to the double number it currently is.</h4><p>For example, if my current number of buckets in the array is 4 you double it so the new size is now 8. Because you reinitialized it, the buckets are empty but since you saved all the key-value entries before this step, it moves us to the next step!</p><pre>self.__init__(new_size)</pre><h4>3. Iterate the list of all key-value entries and for each key-value entry, call the set operation to put that key-value entry in the hash table.</h4><pre>for k,v in temp_entries:</pre><pre>    self.set(k,v)</pre><p>To sum these three steps up, all we’re doing, in a nutshell, is putting all of our key-value pairs in a temporary list. Then, we re-initialize the class which takes in the size of the hash table so we multiply the current size * 2. Finally, we just iterate over the temporary list that is created before all of this and adds each item into the re-initialized hash table by calling the set method on each item.</p><h4><strong>Steps to getting a key-value pair</strong></h4><p>So we’ve now learned a lot about hash tables and if you feel overwhelmed, please don’t! You’re not supposed to learn all of this in one read and to get everything you want to know you’re going to probably want to do a little more researching 🙂There is one more main thing you should know about hash tables, and that’s knowing how you get a specific key-value pair.</p><p>Great! We’ve added all the items we needed in the hash table, now let’s learn how you get a particular key-value pair under the hood.</p><p>Getting a key-value pair is very similar to adding a key-value pair. We first find the index using the hash function, then we access our bucket / linked list and iterate through that.</p><h3><strong>Resources</strong></h3><p>Here are the resources I used to put this article together. I would recommend going through these if you want to go more in-depth about hash tables &amp; dictionaries!</p><ol><li><a href="https://stackoverflow.com/questions/2061222/what-is-the-true-difference-between-a-dictionary-and-a-hash-table/2061406">Hash Table vs Dictionaries</a>, Samuel Klatchko</li><li><a href="https://stackoverflow.com/questions/327311/how-are-pythons-built-in-dictionaries-implemented">How are Python’s built in dictionaries implemented</a>, Praveen Gollakota</li><li><a href="https://www.youtube.com/watch?v=shs0KM3wKv8">Data Structures: Hash Tables</a>, Gayle Laakmann McDowell</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=817772cad688" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning the Linked List Data Structure the fun way]]></title>
            <link>https://medium.com/@erikbatista42/learning-the-linked-list-data-structure-the-fun-way-448b3b2ced19?source=rss-3f884d4a30a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/448b3b2ced19</guid>
            <dc:creator><![CDATA[Erik Batista]]></dc:creator>
            <pubDate>Fri, 17 May 2019 14:01:21 GMT</pubDate>
            <atom:updated>2019-05-17T16:26:18.837Z</atom:updated>
            <content:encoded><![CDATA[<h4>With simple drawings and clear explanations</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-h4Py3XqGwpXWneUIwUuQA.png" /><figcaption>“Make a singly linked list” — google images</figcaption></figure><p><em>Yep, that what I looked like when I was first asked to do a singly linked list.</em></p><p>In this article, we’re just going to touch the surface of a linked list and get an idea of how this data structure works.</p><blockquote>A singly linked list is a data structure made up of a collection of nodes which together represent a sequence. — <a href="https://en.wikipedia.org/wiki/Linked_list">wikipedia</a></blockquote><h4>Woah wait! What’s a NODE?</h4><p>I remember when first hearing about this data structure this was one of my first questions I kept wondering about. It was confusing at first, but it’s actually pretty simple! So let’s start there.</p><p><strong>In a linked list, a node is a class. </strong>A class that you make yourself from scratch. In this node class, each node has a 2 properties.</p><ol><li>A <strong>data </strong>property</li><li>A <strong>pointer</strong> that points to the next node in the sequence(in order).</li></ol><p>Let’s get a visual representation of what a node looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*21wmrK_vbldIsWascMhcoA.png" /><figcaption>Single node</figcaption></figure><p>In this image, the data of this node is “bob” and instead of the node pointer to another node, it points to None. A Node can do that. Keep reading to understand why.</p><p>Since we now have an idea of what a node looks like, let’s see how we can implement that in python code:</p><pre>class Node(): <br>    def __init__(self, data): <br>        self.data = data <br>        self.next = None</pre><pre>if __name__ == &quot;__main__&quot;:<br>    bob_node = Node(“bob”)<br></pre><p>Okay! So that’s just one node. How does it looks like if we have three nodes connected(with the pointers of course) to each other?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4F5kFkZADGj2QlGNE9jdjA.png" /><figcaption>Three connected nodes</figcaption></figure><p>Isn’t that cool?! Let’s look at the code for that:</p><pre>class Node(): <br>    def __init__(self, data): <br>        self.data = data <br>        self.next = None</pre><pre>if __name__ == &quot;__main__&quot;:<br>    a = Node(“bob”)<br>    b = Node(“gary”)<br>    c = Node(“patrick”)</pre><pre>    a.next = b<br>    b.next = c</pre><h4>Singly Linked List</h4><p>Since we know that the linked list is composed of a sequence of nodes, let’s get to know the singly linked list.</p><p>There are a couple of terms we need to know for the linked list to make sense:</p><p><strong>Head — </strong>It’s the very <em>first</em> node of the linked list</p><p><strong>Tail — </strong>It’s The very <em>end</em> node of the linked list</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1vLBJ86bCyYpUy7z_DUx7w.png" /><figcaption>Representation of full singly linked list</figcaption></figure><p>Now that we have a full visual representation of a linked list, let’s implement it!</p><pre>class Node():    <br>    def __init__(self, data):<br>        self.data = data<br>        self.next = None</pre><pre>class Singly_linked_list():    <br>    def __init__(self):        <br>        self.head = None        <br>        self.tail = None</pre><pre>   def is_empty(self):        <br>    &quot;&quot;&quot;Return True if this linked list is empty, or False.&quot;&quot;&quot; <br>       return self.head is None<br>    <br>    def append(self, item): <br>        # Create a new node to hold the given item<br>        new_node = Node(item)       <br>        # Check if this linked list is empty        <br>        if self.is_empty():            <br>            # Assign head to new node<br>            self.head = new_node        <br>        else:            <br>            # Otherwise insert new node after tail                                                                       <br>            self.tail.next = new_node <br>            # Update tail to new node regardless        <br>            self.tail = new_node</pre><pre>if __name__ == &quot;__main__&quot;:    <br>    ll = Singly_linked_list()    <br>    ll.append(&quot;bob&quot;)    <br>    ll.append(&quot;gary&quot;)    <br>    ll.append(&quot;patrick&quot;)    <br>    print(ll)</pre><p>First, we have the node class. Then, we have the linked list class which will contain all the nodes in our singly linked list. When having a singly linked list class, we want to have methods so that we can do things with our linked list. For example, in here we have the <strong>.is_empty()</strong> method to check if the list is empty. It’s pretty simple. If there is no head, there is no linked list.</p><p>Then, we have the .<strong>append(item)</strong> method which adds a node to the end of the linked list.</p><h4>But wait!</h4><p>What if we only have one node? Is there still a head and tail? The answer is yes. If there is one node both the head <strong>and</strong> tail points to that one node. So something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yrXJ5edDmKElF6rnvBx4hA.png" /><figcaption>One node in a singly linked list</figcaption></figure><h4>Traversing through a linked list</h4><p>When we traverse through a linked list, it means that we are moving from one node to the next one. Traversing through the whole linked list means we start from the head node to the tail node. You always have to start traversing from the head to whatever node you need. The nodes doesn’t have an index like arrays do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*RLZbcQ5zqrI3na191lIvYw.jpeg" /><figcaption>Ta Da!</figcaption></figure><p>I hope you enjoyed this article and learned the basics of a singly linked list! If you have some feedback or just want me to add something to this article, comment below!</p><h3>Resources</h3><p>Singly linked lists are really simple data structures once you learn it, and it’s a really good tool to know for solving coding interviews. If you would like to learn more about linked lists, check out these resources below!</p><ol><li><a href="https://en.wikipedia.org/wiki/Linked_list">Linked List</a>, Wikipedia</li><li><a href="http://codingwithalex.com/data-structures-everything-you-need-to-know-about-linked-list/">Data Structures</a>, Alex Casana</li><li><a href="https://medium.com/basecs/whats-a-linked-list-anyway-part-1-d8b7e6508b9d">What’s a linked list, anyway?</a>, Vaidehi Joshi</li><li><a href="https://www.youtube.com/watch?v=njTh_OwMljA&amp;t=192s">Video About Linked List,</a> Hacker Rank</li><li><a href="https://visualgo.net/en/list">Interactive Game</a>, Visual Algo</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=448b3b2ced19" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning to use Dictionaries in Python]]></title>
            <link>https://medium.com/@erikbatista42/learning-to-use-dictionaries-in-python-4b93d3142d8e?source=rss-3f884d4a30a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b93d3142d8e</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Erik Batista]]></dc:creator>
            <pubDate>Tue, 30 Apr 2019 23:17:00 GMT</pubDate>
            <atom:updated>2019-05-01T18:53:07.326Z</atom:updated>
            <content:encoded><![CDATA[<h4>Also called hash, hash map, map, unordered map, hash table, table, associative array</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bjlKOnMugHeLC970_PBxEg.jpeg" /><figcaption>Pinterest: ognature.com</figcaption></figure><p>In this article, we’re not going to dive deep into this data structure. We’re not going to learn how it works under the hood. We’re going to cover the basics of Python dictionaries and learn how to access and manipulate dictionary data.</p><h4>What’s a dictionary?!</h4><p>If we’re going to learn how to use dictionaries, we must make sure we know what they are!</p><blockquote>A dictionary is an unordered collection of entries. Each entry is composed of a key and a value.</blockquote><p>In python, a dictionary is declared with curly braces. We store the entries (sometimes called “key/value” pair) in the dictionary and separate each entry using commas just like the picture below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FTOkvC6CPmoGuAmP5b6RBA.png" /><figcaption>Anatomy of a dictionary</figcaption></figure><h3><strong>Benefits and drawbacks</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/0*uLqbOnvTtY3chXXP" /><figcaption><em>snapshot from </em><a href="https://en.wikipedia.org/wiki/Hash_table"><em>wikipedia</em></a></figcaption></figure><p>The dictionaries main advantage is <strong>speed. </strong>As it shows on the picture above, you can perform search, delete, and insertion operations that will execute in constant time on average. A dictionary also doesn’t store any duplicate keys. We’ll learn more about this later on in the article.</p><p>One of its drawback is that dictionaries use O(num_of_entries) memory space. So keep that in back of your head! Also keep in mind that dictionaries are a <strong>collection of unordered collection of entries. </strong>So if you plan to have sorted data, it’s a bad idea to use this data structure.</p><h3>How does it work?</h3><p>Let’s look at the most common operations used on dictionaries and lets see how to implement them in Python:</p><h4>Inserting a new entry into dictionary</h4><p>Adding a new entry is simple! we just do this -&gt; dictionary_name[key] = value</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*-5KHe-yHEHpYvqQ15Iz1kQ.png" /><figcaption>Inserting an entry</figcaption></figure><h4>Getting a dictionary value ( subscript vs .get(key) )</h4><p>Two ways we can go about this is using the <strong>subscript operator </strong>-&gt; <strong>[</strong>key<strong>]</strong> or we can use the .get(key) method for dictionaries. The .get method returns the key if it exists. If it doesn’t, it just returns none.</p><p>If you’re using the subscript operator like on line 4 in the picture below to get your value, it gets it. But if it doesn’t exist, Python throws an error that the key is not found. Using .get() is more safe!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hX2aQwMn2076853MT-Uimg.png" /><figcaption>Accessing values</figcaption></figure><h4>Removing an entry in dictionary</h4><p>To remove an entry in a dictionary you can use the .pop() method</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*tMKwUnKzuvNy48P1zHyg7Q.png" /><figcaption>Using the .pop(key) method</figcaption></figure><h4><strong>Returning a list of entries in dictionary</strong></h4><p>You can do this by calling the .items() method on a dictionary like below. The <strong>.items() method returns a list of tuples containing the entries.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z79KRle5Mmbz7JKroWbQ3g.png" /><figcaption>.items() representation</figcaption></figure><h4>Iterating through a dictionary</h4><p>This is why it’s important to know the .items() method. Because it allows us to iterate through a dictionary or <em>a list of tuples containing the entries. </em>If we don’t call .items() python raises an error saying “too many values to unpack”. But that’s just if we’re trying to iterate through both<strong> key and value </strong>at the same time. This is like the .enumerate() method you can call on lists so that you can iterate through the index and value at the same time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HxlKFkWfARbLOVBq9ZJSDw.png" /><figcaption>Iterating while using .items() on a dictionary</figcaption></figure><h4><strong>What if we don’t want to use .items() to iterate?</strong></h4><p>Nothing wrong with that! But if you choose to not call a method on the dictionary like .items() you can only iterate through the keys like below!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*CW6ByDGbZKjULoYCqqgFgw.png" /><figcaption>Iterating with no method called on a dictionary</figcaption></figure><p>There are more built in methods that you can use on dictionaries. When I learned about dictionaries this are the things I knew. But I struggled how to use them in coding challenges. Doing coding challenges will help you get use to working with dictionaries and make you think on when you can use them. I recommend to do them in order.</p><h4>1) We are going to treat these small exercises below as a coding challenge. This will help you get familiar with the dictionary and its methods.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cZDhmEVh0ixrL4IC4B-mqA.png" /><figcaption><a href="https://g.co/kgs/3dQkUP">Fundamentals of Python by Kenneth A. Lambert.</a> (PG 190)</figcaption></figure><h4>2) Return a string with the most frequently occurring letter(s) in an input string</h4><p><strong>Sample #1:</strong></p><p>Enter a string:<strong> “An apple a day keeps the doctor away”</strong></p><p>The most frequently occurring letter(s):<strong> “A”</strong></p><p><strong>Sample #2:</strong></p><p>Enter a string:<strong> “Today is Tuesday”</strong></p><p>The most frequently occurring letter(s):<strong> “ADSTY”</strong></p><p>There are many ways to solve this problem. But for dictionary practice, try to solve the problem with a dictionary. This will get you thinking on how to use the dictionary.</p><h4>3) First unique character in a string</h4><p>Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1.</p><p><strong>Note</strong>: You may assume the string contain only lowercase letters.</p><p>Remember to try to solving the problem using a dictionary. This coding challenge is available on L<a href="https://leetcode.com/problems/first-unique-character-in-a-string/">eetcode</a>!</p><h3>Resources</h3><p>Dictionaries are really important, and it’s a really good tool to know for solving coding interviews. If you would like to learn more about dictionaries, you’ll enjoy the resources below!</p><ol><li><a href="https://realpython.com/python-dicts/">Dictionaries in Python</a>, John Sturtz</li><li><a href="https://www.interviewcake.com/concept/python3/hash-map">Hash Table/Hash Map</a>, Cake Labs</li><li><a href="https://docs.python.org/3/library/stdtypes.html#typesmapping">Built-in Types</a>, Python</li><li><a href="https://www.reddit.com/r/learnpython/comments/1qhg9w/finding_the_most_common_letters_in_a_string/">Most common letter(s) in a string</a>, Spasmwaiter</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1/0*GRsX0jMT3YWY6Sqv.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b93d3142d8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding Short Interesting Stories]]></title>
            <link>https://medium.com/@erikbatista42/finding-short-interesting-stories-f0b2a9471ef0?source=rss-3f884d4a30a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0b2a9471ef0</guid>
            <category><![CDATA[medium]]></category>
            <category><![CDATA[humans-of-new-york]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[stories]]></category>
            <dc:creator><![CDATA[Erik Batista]]></dc:creator>
            <pubDate>Wed, 10 Oct 2018 05:06:58 GMT</pubDate>
            <atom:updated>2018-10-10T16:48:28.011Z</atom:updated>
            <content:encoded><![CDATA[<h4>Software Product Development</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4e7Xzl1toHvLk2YGB5Dn2A.png" /></figure><p>Whenever I visit a new city, I am not like most tourists that are captivated by the sights. Rather, I am drawn to the people. I wonder where the people I pass by come from and where they are going. When I moved to San Francisco, I knew that most people were involved in the tech industry in some way. When I walk around the city, I always look at people’s backpacks branded with their company logo. I wonder what their story is and how they contribute to the product whose logo is embroidered on their bag. After all, San Francisco is the mecca for technology. In a world where everyone spends the majority of their leisure time looking down at their cell phones, I often find it difficult to come across short and substantial articles that capture my interest.</p><p>I am drawn to people’s personal stories, and was particularly lured by the small narratives recounting people’s experiences in “Humans of New York”. Rather than read about politics or trending articles, I rather become familiar with the people that make up the fabric of my city by reading about their experiences. Although there is a lot of content on the web, I find it difficult to stumble upon material that is truly engaging. My friends share my same frustration, and wish that there were better tools for serving content to users that is tailored to their particular interests. In my case, I am captivated by topics that have a sociological flavor, and rather spend my time reading articles that touch upon this theme.</p><h3><strong>The Trends</strong></h3><h4><strong>Political</strong></h4><p>Given the intense political climate nowadays, a lot of the content that is served is political in nature. In addition, it is difficult to encounter articles that are not partial to any political party. There is certainly no shortage of material on the web that covers politics. However, there are not a lot of sources that merely provide facts without interjecting an opinion. Many turn to social media platforms like Twitter for their daily digest of current events and, oftentimes, 280 characters can convey powerful messages.</p><h4><strong>Economic/Demographic</strong></h4><p>Considering the amount of free material on the web, most people find it illogical to pay for access to content. Newspapers have been substituted by online subscriptions. Most people are busy, but still want to remain informed about current events or read about subjects that interest them. Tech entrepreneurs might turn to sources like ‘Fast Company’ and ‘Wired’, while business people would rather spend their time reading ‘Forbes’ and ‘Business Insider’. Most millenials probably prefer access to free content that is digitized. On the other hand, an older demographic might opt for printed content.</p><h4><strong>Social</strong></h4><p>People not only want to read, but also want to converse with those who share similar interests. For this reason, digitized content incorporates interactive features like a comments section. Social media sites like Facebook and Twitter have turned reading the news into a social experience. In addition, platforms such as Reddit and Quora allow users to delve into deep discussions on just about any topic.</p><h4>Technological</h4><p>A lot of people, including myself, find themselves reading content that interests them during a commute or break. Given the time shortage, information must be accessible and concise. Mobile devices offer the benefits of accessing content quickly at the palm of your hand. In an age where everyone is looking down at their phones, mobile devices offer users the convenience of having everything at their disposal through one interface.</p><h3>Competitive Analysis</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*2CHqi1qrfaKwEsxR6O1OUA.png" /><figcaption>my competitive analysis of today’s tools to read stories</figcaption></figure><h3><strong>The Current Options and The Problem</strong></h3><p>When you think about media outlets, several platforms come to mind such as:</p><ul><li>Reddit</li><li>Twitter</li><li>Facebook</li><li>Quora</li><li>Medium</li><li>The New York Times</li></ul><p>Although the main goal of these platforms is to serve content, each site has its own flavor. In the past, people turned to news sources like ‘The New York Times’ and magazines like ‘The Economist’ to read up on current trends. Unlike most modern sources, this content is written by journalists and undergoes thorough review before being published. Online publishing platforms, like Medium, have allowed anyone to post their work. These platforms have signaled a shift from the dry and rigid structure of major news sources.</p><p>For even shorter glimpses of current affairs, Twitter has become a popular source. Users can read tweets that condense news articles into 280 characters or less. In addition, Twitter offers a way to keep up with the lives of friends and public figures. Another popular source of information is Reddit, which is a massive forum of topics. Redditors can browse through subreddits, or threads regarding a particular topic, and participate in discussions amongst other users. Platforms like Quora take a question and answer approach where users ask a question and other users, preferably experts on the topic, provide answers.</p><p>Each platform is unique in the way that they transmit information. Whenever I take a breather and need a distraction, I find myself switching between a combination of these applications and am not loyal to a single one. There is a need for a platform where a user can curate his/her own content without the need to browse through multiple sources. Although existing applications offer a wealth of information, they are not customizable. I find myself wasting too much time sifting through content that I am uninterested in. If I can minimize the amount of time that I spend searching for something interesting to read, I can learn more about the topics that truly interest me.</p><h3>User Interviews</h3><p>An application that curates content based on a user’s interest has no particular target audience. Everyone, from adolescents to adults, uses some sort of application for entertainment purposes or to stay informed. I decided to ask around and see what resources people use to read about their interests. I interviewed three people, each of which belongs to a different age bracket. Mariana, 18, is a college student studying programming in San Francisco. Melanie, 26, is a Software Engineer. Lenny, 56, is a business owner. I asked all three interviewees the same set of questions to get a feel for their personal preferences, specifically:</p><ul><li>What do you do when you are bored or distracted?</li><li>Do you use any mobile or web applications for entertainment? If so, which ones?</li><li>What resources do you use to stay informed? Do you prefer to use one or multiple?</li><li>What topics interest you within these resources?</li></ul><p>In answering my questions, all three interviewees used some sort of electronic device as a form of diversion. Whether a cell phone or a tablet, electronics were used to access content. Mariana entertains and informs herself using online resources, particularly social media platforms like Facebook and Twitter. We are both drawn to stories about people’s experiences, and she enjoys looking at posts made by ‘Humans of New York’. Melanie has an online subscription to ‘The New York Times’ to stay updated on current events, but prefers to read physical books for entertainment. She enjoys good writing in general, regardless of the genre, and is subscribed to ‘The New Yorker’ which she accesses online. She is willing to pay for subscriptions if the quality of the writing is better than that of platforms like Medium. Lenny watches the nightly news to stay informed on current events and has an online subscription to ‘The New York Times’. He wakes up early in the mornings and reads only the articles that interest him on his iPad, particularly trending stories. He entertains himself by constantly learning about new topics through online lectures via YouTube. I was able to draw one main conclusion between all three interviewees: there is no single source of information that people frequent for entertainment or information.</p><h3><strong>The Solution</strong></h3><p>The observations of my own behaviors, as well as those of others, has led me to draw one conclusion: there is no single source that people go to for content. While popular platforms like Reddit and Quora contain a wealth of information, it is time consuming to sift through all the articles or threads to find only a few that actually spark your interest.</p><p>My solution would be to scrape data from these platforms and classify it. In order to do this programmatically, I would create text files corresponding to every category. I would then populate each file with keywords that are most commonly seen with respect to that category. For instance, if the category is ‘entertainment’, related words are ‘movie’, ‘actor’, ‘actress’, ‘film’, etc. I would then perform a keyword search of the scraped data against my files in order to classify the data.</p><p>Users would be able to select the category that he/she wishes to read about on the UI. The articles contained within the user’s selection would come from the major content sources, but would all be accessible from a single application. This would not only save them time, but would also maximize their chances of finding something interesting to read. The wireframes below show a use case for my application on a mobile device. If the ‘anecdotes’ category is chosen, a user is directed to a new view containing only anecdotes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*_Zcv6UKG5OsAmjl5CkRWqg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*bbLIP9wLU5mbApCoyauyPg.png" /><figcaption>iOS wireframes for accessing curated content through one platform</figcaption></figure><h3>The Conclusion</h3><p>During my free time, I find myself spending more time looking for something interesting to read than reading something interesting. Too much time is wasted switching back and forth between Reddit, Quora, and Twitter. The perfect solution is to have one singular application where I can curate my own content that comes from my favorite online sources. If we could only see content that interests us, we would not only save time, but also enrich our minds even further.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0b2a9471ef0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>