<?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: Eric Magesho</title>
    <description>The latest articles on DEV Community by Eric Magesho (@ericmagesho).</description>
    <link>https://dev.to/ericmagesho</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%2F196143%2Fdb7153a8-f5a0-4feb-9bcf-83e4e007482b.jpeg</url>
      <title>DEV Community: Eric Magesho</title>
      <link>https://dev.to/ericmagesho</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ericmagesho"/>
    <language>en</language>
    <item>
      <title>INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS IN PYTHON</title>
      <dc:creator>Eric Magesho</dc:creator>
      <pubDate>Mon, 21 Feb 2022 13:23:11 +0000</pubDate>
      <link>https://dev.to/ericmagesho/introduction-to-data-structures-and-algorithms-in-python-dol</link>
      <guid>https://dev.to/ericmagesho/introduction-to-data-structures-and-algorithms-in-python-dol</guid>
      <description>&lt;p&gt;&lt;strong&gt;Data structures and algorithms&lt;/strong&gt; are one of the most common and tricky interview questions in most software development roles. Most beginner developers, especially those who haven't been in a computer science class, always fail terribly. In this tutorial, we will discuss this very important topic at a high level and try as much as possible to make it beginner-friendly. Roll your sleeves up and let's dive right in.&lt;/p&gt;

&lt;h3&gt;
  
  
  DATA STRUCTURES
&lt;/h3&gt;

&lt;p&gt;Let's assume you are building a house. You will need to have the raw materials like wood, cement, blocks, metal etc and apply the right building procedures for you to end up with a complete house. The same happens when building software, You will need the building blocks and specific instructions(or &lt;em&gt;algorithms&lt;/em&gt;) to come up with a better end product. Data structures are the building blocks of software. They are used to organize, store and manage data for efficient access and manipulation. To be a better programmer you have to have a sound knowledge of data structures and algorithms so that you use the right tool for a specific problem. This will enable you to save time, write better code more efficiently.&lt;/p&gt;

&lt;p&gt;There are two major categories of data structures in Python:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Built-in data structures eg&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Lists&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dictionaries&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tuples&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sets.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2.User-defined data structures eg&lt;br&gt;
Linked-list&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Queues&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stack&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Graphs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Heaps.&lt;br&gt;
We shall discuss the most common data structures and how they are implemented in python.&lt;br&gt;
But before we discuss each of these, let's talk briefly about a very important but related subject:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Big O notation
&lt;/h4&gt;

&lt;p&gt;In its simplest term, The &lt;strong&gt;Big O notation&lt;/strong&gt; is used to measure how &lt;em&gt;running time or space requirements&lt;/em&gt; for your program grow as the &lt;em&gt;input size&lt;/em&gt; grows.&lt;br&gt;
In your projects when your solution requires a particular algorithm, it is important to understand how fast or slow it is compared to other options.&lt;br&gt;
consider below function that takes a list of integers and returns the sum:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def find_total(items):
    sum = 0
    for item in items:
        sum += item
    return sum

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

&lt;/div&gt;



&lt;p&gt;When you call the function with a list containing 4 items, the run time is far much less than when you call in with a list containing a billion items. Irrespective of whether you are running the function on a faster machine or not, the runtime can be represented as a linear function like so:&lt;br&gt;
&lt;code&gt;time = an + b&lt;/code&gt;&lt;br&gt;
When calculating the Big O, the rule of the thumb is to keep the fastest growing term and drop any constants. Hence&lt;br&gt;
&lt;strong&gt;&lt;code&gt;time = O(n)&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
It's important to note that Big O establishes the worst-case run-time.&lt;br&gt;
So when choosing what data structure and algorithm to use in your implementations you need to consider the runtime implications.&lt;strong&gt;Use the right tool for a specific problem.&lt;/strong&gt;&lt;br&gt;
You can read more about Big O here:[(&lt;a href="https://www.freecodecamp.org/news/big-o-notation-explained-with-examples/)"&gt;https://www.freecodecamp.org/news/big-o-notation-explained-with-examples/)&lt;/a&gt;]&lt;/p&gt;
&lt;h3&gt;
  
  
  Lists
&lt;/h3&gt;

&lt;p&gt;In python, the list data structure is implemented as a dynamic array. It's a general-purpose and mostly used data structure. You can create a list using either of the three methods below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;list()&lt;/code&gt; - Using the constructor.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;my_list = []&lt;/code&gt; - literal.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[item for item in range(10)]&lt;/code&gt; - using list comprehension.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can access items of a list by using the [] bracket notation eg &lt;code&gt;my_list[0]&lt;/code&gt;.&lt;br&gt;
Looking up an item by index takes &lt;strong&gt;O(1)&lt;/strong&gt;, and looking by value takes &lt;strong&gt;O(n)&lt;/strong&gt;.&lt;br&gt;
check out this tutorial for a comprehensive discussion of Python lists [(&lt;a href="https://www.geeksforgeeks.org/python-list/)"&gt;https://www.geeksforgeeks.org/python-list/)&lt;/a&gt;]&lt;/p&gt;
&lt;h3&gt;
  
  
  Dictionaries
&lt;/h3&gt;

&lt;p&gt;A Dictionary is a collection of unordered data values consisting of Key: Value pairs. The keys in a dictionary are immutable.&lt;br&gt;
You can create a dictionary in python by placing a sequence of keys and values separated by commas in curly braces &lt;strong&gt;{}&lt;/strong&gt;.You can also create a dictionary by using the built-in &lt;strong&gt;dict()&lt;/strong&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Creating an empty Dictionary
My_dict = {}
output
{}

# Creating a Dictionary with dict() method
my_dict = dict({1: 'apples', 2: 'oranges', 3:'Mangoes'})
output
{1:'apples',2:'oranges',3:'Mangoes'}

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

&lt;/div&gt;



&lt;p&gt;You can use the [] notation to access an element in a dictionary using a key eg &lt;code&gt;my_dict[1]&lt;/code&gt;.There is also a &lt;strong&gt;get()&lt;/strong&gt; method you can use to access an element in a dictionary. &lt;br&gt;
You can traverse the dictionary using a for-loop like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#using the keys
for key in my_dict.keys():
    print(key)
#using the values
for value in my_dict.values():
    print(value)
#Using both key,value pairs
for key,value in my_dict.items():
    print(key.value)

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

&lt;/div&gt;



&lt;p&gt;For an extensive discussion of python dictionary please check out this link [(&lt;a href="https://www.geeksforgeeks.org/python-dictionary/)"&gt;https://www.geeksforgeeks.org/python-dictionary/)&lt;/a&gt;]&lt;/p&gt;

&lt;h3&gt;
  
  
  Tuples
&lt;/h3&gt;

&lt;p&gt;A tuple is similar to a list as both are of sequence type, but it's immutable. It's useful for fixed data and is faster than a list.&lt;br&gt;
You can create an empty tuple as below:&lt;br&gt;
&lt;code&gt;empty_tuple = ()&lt;/code&gt;.&lt;br&gt;
All other operations of the sequence type in python apply to tuples.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sets
&lt;/h3&gt;

&lt;p&gt;A set is an unordered collection of items, used to store non-duplicate items. The items themselves are immutable but the set can be mutable. Sets provide fast access to elements than lists.&lt;br&gt;
Sets can also be used to perform mathematical set operations like union, intersection, symmetric difference, etc.&lt;br&gt;
A set is created by placing all the items (elements) inside curly braces {}, separated by a comma, or by using the built-in set() function.ie &lt;code&gt;my_set = set()&lt;/code&gt; or &lt;code&gt;my_set = {2,4,6}&lt;/code&gt;.&lt;br&gt;
A set can have any number of items, of different types(integers, floats, strings etc) but cannot have mutable types eg lists, dictionaries.&lt;br&gt;
For a complete tutorial on python sets, you can check out [(&lt;a href="https://www.programiz.com/python-programming/set)"&gt;https://www.programiz.com/python-programming/set)&lt;/a&gt;].&lt;/p&gt;

&lt;h3&gt;
  
  
  Linked-lists
&lt;/h3&gt;

&lt;p&gt;As we have mentioned above, lists are implemented as dynamic arrays in python. This proves to be inefficient when doing operations on lists eg adding items. Because the list has to be copied to different memory locations and this adds an overhead when the list is big enough. This is what the linked list is trying to solve. While lists use a contiguous memory block to store references to their data, linked lists store references as part of their elements.&lt;br&gt;
Every linked list is composed of nodes-every node has two parts: data and a pointer to the next node.&lt;br&gt;
Linked lists can be used to implement queues and stacks as well as graphs.&lt;br&gt;
Check out this tutorial for a complete discussion of linked lists including examples of implementation in python:&lt;br&gt;
[(&lt;a href="https://www.youtube.com/watch?v=Bd1L64clh34)"&gt;https://www.youtube.com/watch?v=Bd1L64clh34)&lt;/a&gt;]&lt;/p&gt;

&lt;h3&gt;
  
  
  Queues and Stacks
&lt;/h3&gt;

&lt;p&gt;Queues and stacks differ only in the way elements are retrieved. For a queue, you use a First-In/First-Out (FIFO) approach. That means that the first element inserted in the list is the first one to be retrieved.&lt;br&gt;
For a stack, you use a Last-In/Fist-Out (LIFO) approach, meaning that the last element inserted in the list is the first to be retrieved:&lt;br&gt;
This Tutorial[(&lt;a href="https://realpython.com/linked-lists-python/#understanding-linked-lists)"&gt;https://realpython.com/linked-lists-python/#understanding-linked-lists)&lt;/a&gt;] explains these data structures in depth.&lt;/p&gt;

&lt;h2&gt;
  
  
  ALGORITHMS
&lt;/h2&gt;

&lt;p&gt;An algorithm is a finite sequence of well-defined instructions, typically used to solve a class of specific problems or to perform a computation.&lt;br&gt;
There are different classes of algorithms including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Divide and Conquer algorithms&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dynamic programming algorithms&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Greedy algorithms&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Randomized algorithms&lt;br&gt;
And many others.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below are elements of a good algorithm:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Steps should be finite, clear and understandable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There should be a clear description of input and output.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Each step must have a defined output that depends only on inputs in that step or the preceding steps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It must be flexible.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;check out this comprehensive course on freecodecamp for a well-illustrated discussion of popular algorithms and their implementations in python:&lt;br&gt;
[(&lt;a href="https://www.youtube.com/results?search_query=algorithms+python)"&gt;https://www.youtube.com/results?search_query=algorithms+python)&lt;/a&gt;]&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Data structures and algorithms is a huge topic and require a lot of time to study(usually a whole semester of work). The links in this tutorial provide comprehensive discussions on each topic. Feel free to check them out. Also please suggest more resources in the comments section below so that we can learn together.&lt;/p&gt;

&lt;p&gt;Happy coding.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>python</category>
      <category>100daysofcode</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Python 101:An Executive summary</title>
      <dc:creator>Eric Magesho</dc:creator>
      <pubDate>Mon, 14 Feb 2022 10:05:11 +0000</pubDate>
      <link>https://dev.to/ericmagesho/python-101an-executive-summary-2cf8</link>
      <guid>https://dev.to/ericmagesho/python-101an-executive-summary-2cf8</guid>
      <description>&lt;p&gt;This article is for the complete beginners of the python programming language. By the end of the tutorial you should be able to understand among other things :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A brief history of the python language and its place in the modern programming language ecosystem.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Features of the language and common use cases.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An effective way of learning the language and free resources to get started.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next steps.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Let's get started.
&lt;/h2&gt;

&lt;p&gt;Python is a high-level, general-purpose programming language initially designed by Guido van Rossum in 1991, named after “Monty Python's Flying Circus”, a BBC comedy series from the 1970s. The language comes with a wide range of syntactical constructions, standard library functions, and interactive development environment features.&lt;br&gt;
According to the 2021 StackOverflow developer survey, python passed SQL to become the third most popular technology. Python is used by Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify, and several other massive companies. It's one of the four main languages at Google, while Google's YouTube is largely written in Python. Same with Reddit, Pinterest, and Instagram. It offers fantastic career opportunities for any programmer who masters it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Features of Python
&lt;/h2&gt;

&lt;p&gt;Python is a dynamic, high level free open source and interpreted language. It supports both procedural and object-oriented paradigms. Some of the features that make Python the most popular language are listed below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Easy to code - It’s usually much easier to read Python code and much faster to write code in Python than in other languages. E.g compare a C program to just print "Hello world"
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
int main(void)
{
printf("Hello, world\n");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And a python program doing the same:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("Hello world")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty simple, right?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Python is free and open-source- it's readily available on the official website [&lt;a href="https://www.python.org/downloads/"&gt;https://www.python.org/downloads/&lt;/a&gt;]. Python also has a very active and friendly community which makes it easier for beginners to dive in.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Python is portable - that means you can write code on windows and run it on other platforms like Linux, Unix and Mac.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dynamically Typed Language:&lt;br&gt;
Python is a dynamically-typed language. That means the type (for example- int, double, long, etc.) for a variable is decided at run time not in advance because of this feature we don’t need to specify the type of variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Extensible feature:&lt;br&gt;
Python is an Extensible language. We can write some Python code into C or C++ language and also we can compile that code in C/C++ language.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is Python used for?
&lt;/h2&gt;

&lt;p&gt;Python has several use cases among them :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Web development&lt;br&gt;
Several Python frameworks that are particularly powerful to help develop and deploy web applications include  Django, Flask and the new kid on the block, FastApi.These frameworks enable speedy application build with minimal development time&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Machine learning and AI&lt;br&gt;
The practical use of AI and Machine learning has grown tremendously in businesses and organizations.&lt;br&gt;
Python can easily handle the computations necessary to create machine learning models and is responsible for creating many advanced applications, such as facial recognition software.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Game applications&lt;br&gt;
Python is often used by developers for building and designing games.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Software development&lt;br&gt;
Python is used to develop many different applications and platforms across industries for example Instagram and Spotify.&lt;br&gt;
Due to Python's ability to handle a range of complex mathematical tasks, the fintech industry has seen an increase in the use of the python programming language over others.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Data science&lt;br&gt;
Python is relatively easy to learn when used in conjunction with data. As such, Python skills are increasingly in demand across both big and small data-driven organizations.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Learning Python.
&lt;/h2&gt;

&lt;p&gt;As seen above, Python can offer tremendous career opportunities so learning the language in 2022 is your best bet. The challenge for beginners is that the internet is filled with lots and lots of unstructured information making it very difficult to learn effectively.&lt;br&gt;
Below you can find a list of resources for learning the python language from beginner to advanced:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;(&lt;a href="https://www.freecodecamp.org/news/learning-python-from-zero-to-hero-120ea540b567/"&gt;https://www.freecodecamp.org/news/learning-python-from-zero-to-hero-120ea540b567/&lt;/a&gt;) - FreecodeCamp is a free resource to start your web development journey. It offers a nicely curated curriculum in different tracks like Data science, web development etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(&lt;a href="https://www.udemy.com/course/100-days-of-code/"&gt;https://www.udemy.com/course/100-days-of-code/&lt;/a&gt;) - Dr Angela Yu did a fantastic job in this course which might be the only course you will need to master the fundamentals as well as gain the practical knowledge you need by tackling 100 projects in 100 days.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(&lt;a href="https://realpython.com/products/python-basics-book/)-"&gt;https://realpython.com/products/python-basics-book/)-&lt;/a&gt; If you prefer books then you can get the PDF. The guys at(&lt;a href="https://realpython.com/"&gt;https://realpython.com/&lt;/a&gt;) are doing a marvellous job.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(&lt;a href="https://automatetheboringstuff.com/"&gt;https://automatetheboringstuff.com/&lt;/a&gt;) - As well is also a good resource for beginners. It covers both fundamentals as well as practical projects to help you practice.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Next steps
&lt;/h2&gt;

&lt;p&gt;The trick is to practice, practice and practice. As you learn the fundamentals of the language, practice by coding real-life projects. Join the (#100DaysOfCode) challenge to keep yourself accountable.&lt;br&gt;
Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>python</category>
      <category>codenewbie</category>
      <category>100daysofcode</category>
    </item>
  </channel>
</rss>
