<?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: fridahmbithe54</title>
    <description>The latest articles on DEV Community by fridahmbithe54 (@fridahmbithe54).</description>
    <link>https://dev.to/fridahmbithe54</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%2F814712%2Fa964468d-eefa-42e8-9d08-87ee2a7d7312.jpg</url>
      <title>DEV Community: fridahmbithe54</title>
      <link>https://dev.to/fridahmbithe54</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fridahmbithe54"/>
    <language>en</language>
    <item>
      <title>Introduction to data structures and algorithms</title>
      <dc:creator>fridahmbithe54</dc:creator>
      <pubDate>Mon, 28 Feb 2022 06:08:11 +0000</pubDate>
      <link>https://dev.to/fridahmbithe54/introduction-to-data-structures-and-algorithms-548g</link>
      <guid>https://dev.to/fridahmbithe54/introduction-to-data-structures-and-algorithms-548g</guid>
      <description>&lt;p&gt;In this article we shall be discussing various data structures in python such as Lists, dictionaries, tuples, sets, queues, stack and linked lists. A data structure refers to a named location which is used for organizing, managing and storage of data according to their data types. A data algorithm refers to the steps or instructions undertaken with the sole purpose of solving a particular problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of data structures
&lt;/h2&gt;

&lt;p&gt;Data structure are divide into two i.e. Built-in data structures and user defined data structures.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TNkUOC33--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gnigcrvp2gbtlxqjq1g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TNkUOC33--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gnigcrvp2gbtlxqjq1g.png" alt="A diagram showing the different types of data structures and their subdivisions" width="774" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Built-in data structures&lt;/strong&gt;
Refers to data structures that allow a programmer to organize, store and manages data to easily allow data access and modification when need arises. They include; lists, dictionaries, tuples and sets.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Lists
&lt;/h2&gt;

&lt;p&gt;A list refers to an ordered collection items which can be used in creating objects of a particular type. List are always put in between square brackets and separated by commas.&lt;br&gt;
Example of a list;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fruits = ['mango', 'banana', 'apple', 'grapes']
print(fruits)
&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;['mango', 'banana', 'apple', 'grapes']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List elements are accessed using their assigned indexes starting with 0 which is the first element in the list and ending with n-1 where n is the total number of the elements.&lt;br&gt;
example;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(fruits[0])  # prints the element at index 0
print(fruits[0::])  # prints the whole list
print(fruits[2])  # prints the element at index 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;mango
['mango', 'banana', 'apple', 'grapes']
apple
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Adding elements into a list
&lt;/h3&gt;

&lt;p&gt;It can be achieved by using  &lt;em&gt;append()&lt;/em&gt; which adds all the passed element as a single element, &lt;em&gt;extend()&lt;/em&gt;, add single elements at a time and &lt;em&gt;insert()&lt;/em&gt; functions, adds the element passed to the index value and increase the size of the list.&lt;br&gt;
Example;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fruits.append(['watermelon', 'pineapples', 'pawpaw'])
print(fruits)
fruits.extend(['peas', 'pawpaw'])
print(fruits)
fruits.insert(2,'oranges') # 2 shows the index number where the item should be added in the list
print(fruits)
&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;['mango', 'banana', 'apple', 'grapes', ['watermelon', 'pineapples', 'pawpaw']]
['mango', 'banana', 'apple', 'grapes', ['watermelon', 'pineapples'], 'peas', 'pawpaw']
['mango', 'banana', 'oranges', 'apple', 'grapes', ['watermelon', 'pineapples'], 'peas', 'pawpaw']

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Dictionaries
&lt;/h2&gt;

&lt;p&gt;They are used to store key-value pairs. They can be created either using Cali brackets {} or function brackets ().&lt;br&gt;
Example;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_stuff = {'lunch': 'burger', 'breakfast': 'Toast'}
print(my_stuff['lunch'])
my_stuff['dinner']= 'pasta'
print(my_stuff['dinner'])
print(my_stuff)
&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;burger
pasta
{'lunch': 'burger', 'breakfast': 'Toast', 'dinner': 'pasta'}

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Changing and adding key value pairs
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_stuff['dinner']= 'pasta'
print(my_stuff['dinner'])  # adding key-value pair
my_stuff['lunch'] = 'pilau'  # changing key-value pair
print(my_stuff)

&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;pasta
{'lunch': 'pilau', 'breakfast': 'eggs', 'dinner': 'pasta'}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Tuples
&lt;/h2&gt;

&lt;p&gt;They are similar to lists are with the exception that the data once entered into the tuple cannot be changed no matter what.&lt;br&gt;
Example;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_tuple = (1, 2, 3)
print(my_tuple)
my_tuple = my_tuple + ('python', 'java')  # appending elements in a tuple
print(my_tuple)
&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;(1, 2, 3)
(1, 2, 3, 'python', 'java')

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

&lt;/div&gt;



&lt;p&gt;accessing elements in tuples is just like in list by using the elements index i.e.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(my_tuple[3])
&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;python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Sets
&lt;/h2&gt;

&lt;p&gt;Sets are a collection of unordered elements that are unique in that even if data is entered in more than one time it will only appear once in the set. For example;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = {1,2,2,2,3,3,3,4,5}
print(x)

&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;{1, 2, 3, 4, 5}

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;User-defined data structures&lt;/strong&gt;
These are data structures that aren't supported by python but can be programmed to reflect the same functionality using concepts supported by python are user-defined data structures. They include; queues, stack, linked lists, trees, Hashmaps and graphs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Queues
&lt;/h2&gt;

&lt;p&gt;They are linear structure that allows insertion of elements from one end and deletion from the other. They use First In First Out(FIFO) methodology for their operations. The end which allows deletion is known as the front of the queue and the other end is known as the rear end of the queue. &lt;/p&gt;

&lt;h2&gt;
  
  
  Tree
&lt;/h2&gt;

&lt;p&gt;An hierarchical data structure with the top most part of it being the root i.e the starting point and the finishing points are called leaves. They are used for the storage of non linear data with hierarchical structure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Graph
&lt;/h2&gt;

&lt;p&gt;Refers to a non-linear data structure which is made up of nodes and edges.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hashmap
&lt;/h2&gt;

&lt;p&gt;Are indexed data structures that use hash functions to compute  an index with a key into an array of slots. Its value is mapped to the slot with the corresponding index. The key is unique and immutable. In Python, dictionaries are examples of hash maps.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Introduction to Modern Python</title>
      <dc:creator>fridahmbithe54</dc:creator>
      <pubDate>Sun, 13 Feb 2022 20:09:48 +0000</pubDate>
      <link>https://dev.to/fridahmbithe54/introduction-to-modern-python-1mkn</link>
      <guid>https://dev.to/fridahmbithe54/introduction-to-modern-python-1mkn</guid>
      <description>&lt;p&gt;Python is a popular programming language with the most simple syntax which enables developers to write smaller lines of code as compared to other programming languages. Python was designed for readability, and has some similarities to the English language with influence from mathematics. It uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses. Also, it relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes while other programming languages often use curly-brackets for this purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Python syntax
&lt;/h2&gt;

&lt;p&gt;Python syntax can be executed by writing directly in the Command Line or by creating a python file on the server, using the .py file extension which is the run in the command line. &lt;/p&gt;

&lt;h2&gt;
  
  
  Commenting in python
&lt;/h2&gt;

&lt;p&gt;comments are used to make python code/ program more readable, provide further explanation and also, during testing to prevent execution of certain lines of code. A comment starts with the # symbol.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Variables in python
&lt;/h2&gt;

&lt;p&gt;Variables are containers for storing data values.&lt;br&gt;
Python has no command for declaring a variable instead it is created after assigning values.&lt;br&gt;
&lt;code&gt;x = 10&lt;br&gt;
y = "Fridah"&lt;br&gt;
print(x)&lt;br&gt;
print(y)&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Also, you can get the type of the function by :&lt;br&gt;
&lt;code&gt;x = 10&lt;br&gt;
y = "Fridah"&lt;br&gt;
print(type(x))&lt;br&gt;
print(type(y))&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
It is important to note that variable names are case-sensitive hence varA cannot overwrite varB&lt;br&gt;
To gain better understanding of python it is adviced to try hands on projects and hence lets create a simple guessing game:&lt;br&gt;
`### GET GUESS&lt;br&gt;
import random&lt;/p&gt;

&lt;p&gt;def get_guess():&lt;br&gt;
    return input("what is your guess")&lt;/p&gt;

&lt;h3&gt;
  
  
  GENERATE COM CODE 123
&lt;/h3&gt;

&lt;p&gt;def generate_code():&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;digits = [str(num) for num in range(10)]

random.shuffle(digits)
return digits[:3]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  take user guess and code and compare the no in a loop and create a list of clues according to matching parameters
&lt;/h3&gt;

&lt;p&gt;def generate_clues(code,user_guess):&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if user_guess == code:
    return "code cracked"

clues = []   

for ind, num in enumerate(user_guess):
    if num == code[ind]:
        clues.append("match")
    elif num in code:
        clues.append("close")

if clues == []:
    return ["nope"]
else:
    return clues
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;print('welcome code breaker!')&lt;/p&gt;

&lt;p&gt;secret_code = generate_code()&lt;/p&gt;

&lt;p&gt;clue_report =[]&lt;/p&gt;

&lt;p&gt;while clue_report != "CODE CRACKED!":&lt;br&gt;
     guess = get_guess()&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; clue_report = generate_clues(guess,secret_code)
 print("here is the result of your guess:")
 for clue in clue_report:
     print(clue)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;x = get_guess()&lt;br&gt;
print(type(x[0]))`&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
