<?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: Gitau20</title>
    <description>The latest articles on DEV Community by Gitau20 (@gitau20).</description>
    <link>https://dev.to/gitau20</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%2F813771%2F443da89a-c95b-408b-b853-db820f455bc6.png</url>
      <title>DEV Community: Gitau20</title>
      <link>https://dev.to/gitau20</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gitau20"/>
    <language>en</language>
    <item>
      <title>Introduction to Data Structures and Algorithms with Python</title>
      <dc:creator>Gitau20</dc:creator>
      <pubDate>Mon, 21 Feb 2022 02:34:11 +0000</pubDate>
      <link>https://dev.to/gitau20/introduction-to-data-structures-and-algorithms-with-python-28jc</link>
      <guid>https://dev.to/gitau20/introduction-to-data-structures-and-algorithms-with-python-28jc</guid>
      <description>&lt;p&gt;Data structures and data algorithms are integral tools to a programmer. &lt;strong&gt;Data structures&lt;/strong&gt; in Python deal with the organization and storage of data in the memory while the computer is processing it. &lt;strong&gt;Python algorithms&lt;/strong&gt; refers to detailed set of instructions that helps in the processing of data for a specific purpose. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DATA STRUCTURES IN PYTHON&lt;/strong&gt;&lt;br&gt;
They are a way of organizing and storing data. Data structures are classified into primitive data types and non-primitive data types. Primitive data types include integers, float, strings and boolean. The non-primitive data types include list, tuples, dictionaries and sets. In addition, there is user-defined data structures in Python which are stack, queue, linked list, tree, graph and hashmap.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Primitive Data Structures&lt;/strong&gt;&lt;br&gt;
These are data structures that stores the data of only one type. Types of primitive data structures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Integers&lt;/em&gt;: This data type is used to represent numerical data, that is, positive or negative whole numbers without a decimal point. For example, -4, 6, 21.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Float&lt;/em&gt;: Used to represent rational numbers usually in decimal point like 2.673, 1.443.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;String&lt;/em&gt;: It is created by a series of characters within '' or"". To concatenate more than two strings, we use '+'. For examples; 'red', 'Zhan'.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Boolean&lt;/em&gt;: Used mainly in conditional expressions taking the form of 'TRUE' or 'FALSE'.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Non-Primitive Data Structures&lt;/strong&gt;&lt;br&gt;
Type of data structure that can store the data of more than one type.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lists: Used to store a collection of data enclosed in [] and separated by , . It is mutable and applicable to append(), remove(), insert() e.t.c&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;todo= ['exercise', 'cleaning', 'assignments']
todo.append('eat')
print(todo)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;['exercise', 'cleaning', 'assignments', 'eat']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Tuples: Similar to lists but immutable and enclosed n ().  It ensures the values enclosed are not manipulated. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;todo= ('cook','clean','code','sleep')
print(todo)
print(todo[0:2])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;('cook', 'clean', 'code', 'sleep')
('cook', 'clean')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Dictionaries: Involves a key associated with a value in a key-value pair. The key-value pair are in {} syntax to create a dict. Each key-value pair is separated by a comma, and within a pair the key and value are separated by a colon :
Syntax
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user = { 
    "name" : 'Liz', 
    "age" : 25,
    "height" : "173"
    }
print(user)
print(user['age'])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'name': 'Liz', 'age': 25, 'height': '173'}
25
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Sets: Similar to a list except that it is unordered. It can store heterogenous data and it is mutable. Creating a set enclosed in a curly bracket {}.
Syntax
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set1 = {'Tate', 22, 163, True}
print(set1)
print(set1.pop())
print(set1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{True, 'Tate', 163, 22}
True
{'Tate', 163, 22}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;User-Defined Data Structures&lt;/strong&gt;&lt;br&gt;
Stacks: Linear data structures in Python stored with principle of FIFO or LIFO. Functions related to its operations are pop(), push(), size() etc.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Queue: Similar to stacks, they are linear data structures but store data based on FIFO principle. Operations related to Queue include Enqueue (adding elements), Dequeue (deleting elements), Front and Rear. Like Stacks, Queues can be implemented using modules and data structures from the Python library – list, collections.deque, and queue.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tree: Non-linear data structures in Python. The properties of a Tree are one node is designated the root node, other than the root, every other node has an associated parent node, and each node can have an arbitrary number of children nodes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Linked List: Linear data structure that contains a series of data elements joined together via links. They are implemented using the concept of nodes.&lt;br&gt;
Creating a Linked list. Create a Node class containing some data and a pointer Next which will be used to point to the next node. &lt;br&gt;
Syntax&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Node:
  def__init__(self, data, next=None):
    self.data = data
    self.next = next
s = Node(5)
print(s.data)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Graph: Pictorial representation of a set of objects in Python. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;HashMaps:a Hash function generates the address or index value of the data element. The index value serves as the key to the data value allowing faster access of data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;DATA ALGORITHMS IN PYTHON&lt;/strong&gt;&lt;br&gt;
An Algorithm is a procedure for solving a problem. It describes a sequence of operations then when performed will result in a solution to a problem. In order to analyze algorithms, one needs to develop some tools to understand how algorithms behave as a function of the problem size.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple Recursive Algorithms: Recursion is the process of defining something in terms of itself. Consider a factorial example;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def factorial(x):
    """This is a recursive function
    to find the factorial of an integer"""

    if x == 1:
        return 1
    else:
        return (x * factorial(x-1))


num = 3
print("The factorial of", num, "is", factorial(num))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The factorial of 3 is 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Divide and Conquer Algorithm: Is the strategy of solving a complex problem by dividing it into smaller sub-problems, solving them and combine to get the desired output. Consider a Fibonacci Sequence.
Syntax of Divide and Conquer
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fib(n)
    If n &amp;lt; 2, return 1
    Else , return f(n - 1) + f(n -2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which differs from the dynamic overall approach of Fibonacci Sequence.&lt;/p&gt;

&lt;p&gt;Hopefully, this will give you a kickstart into understanding Data Structures and Data Algorithms. Additional input is welcomed. &lt;/p&gt;

</description>
      <category>python</category>
      <category>datastructures</category>
      <category>dataalgorithms</category>
      <category>beginners</category>
    </item>
    <item>
      <title>INTRODUCTION TO MODERN PYTHON</title>
      <dc:creator>Gitau20</dc:creator>
      <pubDate>Mon, 14 Feb 2022 02:07:28 +0000</pubDate>
      <link>https://dev.to/gitau20/python-101-introduction-to-modern-python-2j03</link>
      <guid>https://dev.to/gitau20/python-101-introduction-to-modern-python-2j03</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction To Python&lt;/strong&gt;&lt;br&gt;
Python is an interpreted high-level language created by Guido Van Rossum and released in 1991. Python is the best solution in many domains from web application, data analysis, data science , machine learning, Automation, data wrangling and AI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common Features Provided By Python&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Simplicity&lt;/em&gt;: Think less of the syntax of the language and more of the code.&lt;br&gt;
&lt;em&gt;Open Source&lt;/em&gt;: A powerful language and it is free for everyone to use and alter as needed.&lt;br&gt;
&lt;em&gt;Portability&lt;/em&gt;: Python code can be shared and it would work the same way it was intended to, seamless and hassle-free.&lt;br&gt;
&lt;em&gt;Being Embeddable &amp;amp; Extensible&lt;/em&gt;: Python can have snippets of other languages inside in to perform certain functions.&lt;br&gt;
&lt;em&gt;Being Interpreted&lt;/em&gt;: The worries of large memory tasks and other heavy CPU tasks are taken care of by Python itself leaving you to worry only about coding.&lt;br&gt;
&lt;em&gt;Huge Amounts of Libraries&lt;/em&gt;: Python has you covered in Data Science &amp;amp; Wed Development.&lt;br&gt;
&lt;em&gt;Object Orientation&lt;/em&gt;: Objects help breaking down complex real-life problems such that they can be coded and solved to obtain solutions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python Basics&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Section 1: Program Flow&lt;/strong&gt;&lt;br&gt;
A program could be long and complicated but it is built of simple parts.&lt;br&gt;
&lt;em&gt;Variable&lt;/em&gt;: Helps keep track of the information we need to successfully execute a program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_name = 'Liz'
my_age = 25
my_favorite_number = 3
has_pet= False

print('My name is', my_name)
print('My age is', my_age)
print('My favorite number is', my_favorite_number)
print('I own a pet:', has_pet)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;String&lt;/em&gt;: Is a sequence of characters. Integer refers to whole numbers. A floating number refers to decimal number. Bool or boolean refers to either True or False.&lt;br&gt;
&lt;em&gt;Functions&lt;/em&gt;: Allow us to define a task we would like the computer to carry out based on input. We define functions using &lt;strong&gt;def&lt;/strong&gt;. For example, write a function which takes in a say-hello variable and print out "Hello World".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Write a function, say_hello which takes in a name variable and print out "Hello name". say_hello("World") should print "Hello World".

 def say_hello(name):
  print("Hello {}".format(name)

say_hello("World"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Syntax&lt;/em&gt;: This refers to the rules of organizing code to determine which part is the function and which part is the argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def codey():
    print('codey is running')
    print('exiting without returning a value')

codey()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Conditionals and Logic&lt;/em&gt;: We'll want the computer to take action only if under certain conditions. Logic is determined to return either true or false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 6
y = 2

print(x &amp;gt; 4 and y &amp;gt; 1)
print(x &amp;gt; 7 and y &amp;gt; 1)
print(x &amp;gt; 7 or y &amp;gt; 1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Iteration&lt;/em&gt;: This refers to repetitive loops to execute the same code as many times as possible. Most basic is while loop which keeps on executing as long as the condition after while is true.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 0
while x &amp;lt; 10:
    print(x)
    x = x + 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Section 2: Data Structures (Lists, Tuples, Dictionary &amp;amp; Sets)&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;List&lt;/em&gt;: Ordered collection of items using square bracket. Let's try creating a list of to-do.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;todo= ['exercise', 'cleaning', 'assignments']
todo.append('eat')
print(todo)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Tuples&lt;/em&gt;: It is similar to a list with major difference that it is immutable. We create using parentheses ()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
todoo= ('cook','clean','code','sleep')
print(todoo)
print(todoo[0:2])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Dictionary&lt;/em&gt;: Involves a key associated with a value in a key-value pair. The key-value pair are in {} syntax to create a dict. Each key-value pair is separated by a comma, and within a pair the key and value are separated by a colon :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user = { 
    "name" : 'Liz', 
    "age" : 25,
    "height" : "173"
    }
print(user)
print(user['age'])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Set&lt;/em&gt;: Similar to a list except that it is unordered. It can store heterogenous data and it is mutable. Creating a set enclosed in a curly bracket {}.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set1 = {'Liz', 25, 173, True}
print(set1)
print(set1.pop())
print(set1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The print out is ordered differently from the input. We can add or remove items in the set.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set1.add('True')
print(set1)
set1.update([59.2, 'black'])
print(set1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With a kick start to basic coding, have fun at it!&lt;/p&gt;

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