<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:g-custom="http://base.google.com/cns/1.0" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
  <channel>
    <title>Python Start Blog</title>
    <link>https://www.pythonstart.com</link>
    <description>Python tutorials for web applications, analysis, and deep learning</description>
    <atom:link href="https://www.pythonstart.com/feed/rss2" type="application/rss+xml" rel="self" />
    <image>
      <title>Python Start Blog</title>
      <url>https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/PythonStart+192x192.png</url>
      <link>https://www.pythonstart.com</link>
    </image>
    <item>
      <title>Regular expressions in Python on Raspberry Pi</title>
      <link>https://www.pythonstart.com/regular-expressions-in-python-on-raspberry-pi</link>
      <description>Learn how to use regular expressions in Python to help sift through large amounts of text input. In this blog post, we will show you the process step-by-step by extracting story passages from an HTML file.</description>
      <content:encoded>&lt;h3&gt;&#xD;
  
                  
         Regular expressions are a powerful tool to parse and validate text input
        
                &#xD;
&lt;/h3&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;div&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/div&gt;&#xD;
  
                  
         Python includes many built-in functions to work with strings, but as you start working with increasing volumes of text input, you need a more powerful and flexible way to validate and format text. As an example, below is a screenshot of a simple Python program running on a Raspberry Pi. This program opens an HTML file called
         
                  &#xD;
  &lt;a href="https://drive.google.com/file/d/13FUlWDZF0E7BxZ4uSqQ7JE8AdXUtMI6A/view?usp=sharing" target="_blank"&gt;&#xD;
    &lt;font&gt;&#xD;
      
                      
           Good morning.html
          
                    &#xD;
    &lt;/font&gt;&#xD;
  &lt;/a&gt;&#xD;
  
                  
         , stores the contents of the file in memory as a string and then prints the string to the console.
         
                  &#xD;
  &lt;div&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/div&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div&gt;&#xD;
  &lt;a&gt;&#xD;
    &lt;img src="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Introducing+regular+expressions.png" alt="Regular expressions quickly sift through text input"/&gt;&#xD;
  &lt;/a&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            The file contents look disorganized and a bit overwhelming when viewed as a string, but if you
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;a href="https://drive.google.com/file/d/13FUlWDZF0E7BxZ4uSqQ7JE8AdXUtMI6A/view?usp=sharing" target="_blank"&gt;&#xD;
      
                      
           download the HTML file
          
                    &#xD;
    &lt;/a&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            and then open it in a web browser, you will discover that it is a very simple, interactive story.
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            ﻿
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div&gt;&#xD;
  &lt;a&gt;&#xD;
    &lt;img src="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Story+HTML.png" alt="HTML story file as it appears in a web browser"/&gt;&#xD;
  &lt;/a&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;div&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/div&gt;&#xD;
  
                  
         Inside the HTML file, there is a lot of text. If you look closely, you will notice the story text is prefaced with an HTML tag,
         
                  &#xD;
  &lt;b&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           &amp;lt;tw-storydata&amp;gt;
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/b&gt;&#xD;
  
                  
         . In this example, we are only interested in the story text, so we decide to extract certain portions of the file using regular expressions.
         
                  &#xD;
  &lt;div&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/div&gt;&#xD;
  &lt;div&gt;&#xD;
    
                    
          To do this, we start by importing the regular expression module with the 
          
                    &#xD;
    &lt;span&gt;&#xD;
      &lt;b&gt;&#xD;
        
                        
            import re
           
                      &#xD;
      &lt;/b&gt;&#xD;
    &lt;/span&gt;&#xD;
    
                    
           statement. Next, we read in the file contents and store it in a string. Then we search the file contents for the
          
                    &#xD;
    &lt;span&gt;&#xD;
      &lt;b&gt;&#xD;
        
                        
            &amp;lt;tw-storydata&amp;gt;
           
                      &#xD;
      &lt;/b&gt;&#xD;
    &lt;/span&gt;&#xD;
    
                    
          tag using the 
          
                    &#xD;
    &lt;span&gt;&#xD;
      &lt;b&gt;&#xD;
        
                        
            re.search()
           
                      &#xD;
      &lt;/b&gt;&#xD;
    &lt;/span&gt;&#xD;
    
                    
           method. Take a look at the code below, then let's dive into the details of the regular expression.
         
                  &#xD;
  &lt;/div&gt;&#xD;
  &lt;div&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/div&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           '''Regular expressions in Python'''
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           import
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           re
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           # Code to open the local file if you have downloaded it
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           with
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           open(
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "Good morning.html"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           )
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           as
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           f:
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
             file_text = f.read()
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           story_data = re.search(
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           '\
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           &amp;lt;tw-storydata.*?\
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           name="(?P&amp;lt;story_name&amp;gt;.*?)"\
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           .*&amp;lt;/tw-storydata&amp;gt;'
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           , file_text)
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           print(
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "Story name: '"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           + story_data.group(
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "story_name"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ) +
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "'"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           )
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ﻿
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           While the regular expression above may look complicated, the goal is simple: we want to find and store the story name. Let's look at it step by step to see how it works:
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;ol&gt;&#xD;
    &lt;li&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             We start by searching for all of the story data. This is the text between the
            
                        &#xD;
        &lt;/span&gt;&#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            &amp;lt;tw-storydata&amp;gt;
           
                      &#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             opening and closing HTML element
            
                        &#xD;
        &lt;/span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      
                      
           To do this, we pass the
           
                      &#xD;
      &lt;span&gt;&#xD;
        
                        
            re.search()
           
                      &#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             method a string parameter that contains the regular expression to describe what we are seeking
            
                        &#xD;
        &lt;/span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      
                      
           Start with a backslash character (
           
                      &#xD;
      &lt;span&gt;&#xD;
        
                        
            \
           
                      &#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            ) to wrap to the next line to make the regular expression easier to read
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      
                      
           Add the
           
                      &#xD;
      &lt;span&gt;&#xD;
        
                        
            &amp;lt;tw-storydata
           
                      &#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             opening element that we are looking for
            
                        &#xD;
        &lt;/span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      
                      
           The period character (
           
                      &#xD;
      &lt;span&gt;&#xD;
        
                        
            .
           
                      &#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            ) indicates that we are looking for any character
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      
                      
           The asterisk character (
           
                      &#xD;
      &lt;span&gt;&#xD;
        
                        
            *
           
                      &#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            ) modifies the search to look for any number of characters
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      
                      
           The question mark (
           
                      &#xD;
      &lt;span&gt;&#xD;
        
                        
            ?
           
                      &#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             ) modifies the search to be non-greedy, so the search will stop at the first instance of
            
                        &#xD;
        &lt;/span&gt;&#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            name="
           
                      &#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             encountered after the
            
                        &#xD;
        &lt;/span&gt;&#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            &amp;lt;tw-storydata
           
                      &#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             opening element
            
                        &#xD;
        &lt;/span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      
                      
           Another period + asterisk + question mark + closing angled bracket (
           
                      &#xD;
      &lt;span&gt;&#xD;
        
                        
            .*?&amp;gt;
           
                      &#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            ) indicates a non-greedy search for a closing bracket
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      
                      
           The next step is to look for and capture the story name, so we search for
           
                      &#xD;
      &lt;span&gt;&#xD;
        
                        
            name="
           
                      &#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
              attribute then use the Python syntax for a
            
                        &#xD;
        &lt;/span&gt;&#xD;
      &lt;/span&gt;&#xD;
      &lt;a href="https://docs.python.org/3.8/howto/regex.html" target="_blank"&gt;&#xD;
        
                        
            named group
           
                      &#xD;
      &lt;/a&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             syntax
            
                        &#xD;
        &lt;/span&gt;&#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            (?P&amp;lt;story_name&amp;gt;.*?)
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            We round out the search with the closing element to validate that the structure conforms to our expectations.
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
  &lt;/ol&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           Once the regular expression has run, we print out the story name by looking up the named group, which we called "
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           story_name"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           .
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           for
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            passage
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           in
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            re.findall(
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           '\
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           &amp;lt;tw-passagedata.*?\
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           name="(.*?)"\
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           .*?&amp;gt;\
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           (.*?)\
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           &amp;lt;/tw-passagedata&amp;gt;'
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           , file_text):
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
              print(passage[0] +
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ": '"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            + passage[1] +
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "'"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           )
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           The snippet of code finds and captures each passage within the story. Here's how it works:
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;ol&gt;&#xD;
    &lt;li&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            We loop through all the passages that are found match the pattern we define
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             The
            
                        &#xD;
        &lt;/span&gt;&#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            &amp;lt;tw-passagedata&amp;gt;
           
                      &#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             elements have a variety of attributes, but we only capture text within
            
                        &#xD;
        &lt;/span&gt;&#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            name=""
           
                      &#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             by using capturing groups with the
            
                        &#xD;
        &lt;/span&gt;&#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            (.*?)
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             We also capture the actual passage by doing a non-greedy search for the closing angle bracket
            
                        &#xD;
        &lt;/span&gt;&#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             .*?&amp;gt;
            
                        &#xD;
        &lt;/span&gt;&#xD;
      &lt;/span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            then use another capturing group
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            We then print the passage name and the actual passage text.
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
  &lt;/ol&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            Ready to give it a try? Jump in and play with
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;a href="https://colab.research.google.com/drive/1JJlMe9nr11wRrtDGHQ1YgCUScuyH3w7w?usp=sharing" target="_blank"&gt;&#xD;
      
                      
           this example
          
                    &#xD;
    &lt;/a&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           , complete with the code needed to import the HTML file from Google Drive.
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    
                    
          ﻿Follow along with
          
                    &#xD;
    &lt;a href="https://www.youtube.com/watch?v=PRkZv5TAa9s" target="_blank"&gt;&#xD;
      
                      
           this video
          
                    &#xD;
    &lt;/a&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            to help you see how to run this on a Raspberry Pi. Let us know if you have any questions by leaving a comment below.
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;</content:encoded>
      <enclosure url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Regular+expressions.png" length="516691" type="image/png" />
      <pubDate>Sun, 28 Jun 2020 04:05:53 GMT</pubDate>
      <author>info@pythonstart.com (Python Start)</author>
      <guid>https://www.pythonstart.com/regular-expressions-in-python-on-raspberry-pi</guid>
      <g-custom:tags type="string">Capturing groups,Regular expressions,Named capturing groups,Python</g-custom:tags>
      <media:content medium="image" url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Regular+expressions.png">
        <media:description>thumbnail</media:description>
      </media:content>
      <media:content medium="image" url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Regular+expressions.png">
        <media:description>main image</media:description>
      </media:content>
    </item>
    <item>
      <title>Solving linear programming problems in Python with PuLP</title>
      <link>https://www.pythonstart.com/solving-linear-programming-problems-in-python-with-pulp</link>
      <description>See how to solve a staffing problem with PuLP, a linear programming toolkit for Python. In this post, we consider a hospital nursing staff scheduling problem.</description>
      <content:encoded>&lt;h3&gt;&#xD;
  
                  
         See how to solve a staffing problem with PuLP, a linear programming toolkit for Python
        
                &#xD;
&lt;/h3&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  
                  
         Linear programming is a way to find ideal solutions to linear functions with multiple variables. For example, reducing project timelines by minimizing critical paths or maximizing revenue with an optimal product mix.
         
                  &#xD;
  &lt;div&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/div&gt;&#xD;
  &lt;div&gt;&#xD;
    
                    
          To better understand the benefits of linear programming in real world scenarios, consider the
          
                    &#xD;
    &lt;a href="https://pdfs.semanticscholar.org/11e8/17ddcdaba61d66f299f7797d987cd1355763.pdf" target="_blank"&gt;&#xD;
      &lt;font&gt;&#xD;
        
                        
            2014 paper by Mr. B.Satheesh Kumar, Ms. G. Nagalakshmi and Dr. S. Kumaraguruabout
           
                      &#xD;
      &lt;/font&gt;&#xD;
    &lt;/a&gt;&#xD;
    
                    
          . The authors studied and optimized a hospital's scheduling process to maximize fairness for individual nurses while satisfying a variety of hospital requirements. An algorithm was used, consisting of a set of linear functions and variables to describe the staffing parameters, and then linear programming was used to minimize the number of staff required while meeting hospital requirements and maximizing fairness among the individual nurses.
         
                  &#xD;
  &lt;/div&gt;&#xD;
  &lt;div&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/div&gt;&#xD;
  &lt;div&gt;&#xD;
    
                    
          Creating optimal schedules for hospital nursing staff is complex. Schedules must balance work hours among the nurses while adhering to strict healthcare requirements. For example, nurses may be subject to a maximum number of consecutive workdays and a minimum amount of rest time between shifts. In addition, hospitals typically need to minimize costs, while ensuring that they have sufficient staff for each time period.
         
                  &#xD;
  &lt;/div&gt;&#xD;
  &lt;div&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/div&gt;&#xD;
  &lt;div&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           Nurses report at the hospital at the beginning of each period and work for 8 consecutive hours. The hospital wants to determine the minimal number of nurses to be employed so that there will be a sufficient number of nurses available for each period.         
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/div&gt;&#xD;
  &lt;div&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;br/&gt;&#xD;
    &lt;/span&gt;&#xD;
  &lt;/div&gt;&#xD;
  &lt;div&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           To demonstrate how linear programming can help, we start by solving an example in Excel. Blue cells represent inputs, yellow cells represent variables and the orange cell represents our objective function. In this case, we want to minimize the total number of nurses required, while meeting certain minimum staffing levels for each 4-hour time window. The nurse staffing schedule is represented in an Excel table, with 4-hour time windows as rows, 8-hour shifts as columns and a blue matrix of 1s and 0s to show how shifts overlap.
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/div&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div&gt;&#xD;
  &lt;a&gt;&#xD;
    &lt;img src="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Hospital+Nurse+Staffing+-+before+solving.png" alt="4-hour time windows and 8-hour shifts represented in an Excel spreadsheet"/&gt;&#xD;
  &lt;/a&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           To make this model easier to manage, four named ranges are described in the gray table on the far right:
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;ol&gt;&#xD;
    &lt;li&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            The minimum number of nurses for each 4-hour time window are listed in the right-most blue column
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            The number of nurses needed for each 8-hour shift is shown in the row of yellow cells
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            Definitions of which shifts work each 4-hour time window are defined in the blue cells at C4:H9
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            The total number of nurses working during any given 4-hour time window are shown in column I
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
  &lt;/ol&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           These cell ranges are defined and can be viewed in Excel's Name Manager from the "Formulas" Ribbon tab.
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div&gt;&#xD;
  &lt;a&gt;&#xD;
    &lt;img src="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Hospital+Nurse+Staffing+-+Name+Manager.png" alt="Named ranges can be viewed in Excel's Name Manager"/&gt;&#xD;
  &lt;/a&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           This sheet automatically optimizes the schedule using Solver, an Excel add-in. Solver automatically adjusts the default values in the yellow cells to optimize staffing for each 8-hour shift, ensuring adequate staff for each 4-hour window and minimizing the total number of nurses required.
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div&gt;&#xD;
  &lt;a&gt;&#xD;
    &lt;img src="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Hospital+Nurse+Staffing+-+Solver+Parameters.png" alt="Solver Parameters"/&gt;&#xD;
  &lt;/a&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           Before we run Solver, notice that our objective is to minimize the total number of nurses required, subject to two types of constraints:
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;ol&gt;&#xD;
    &lt;li&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            The number of nurses must be an integer (whole number) to avoid fractional staffing numbers
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
    &lt;li&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            The number of nurses working in any 4-hour window must be greater than or equal to the minimum
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/li&gt;&#xD;
  &lt;/ol&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           Once all of the Solver parameters are set, Solver is run to find an optimal solution.
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div&gt;&#xD;
  &lt;a&gt;&#xD;
    &lt;img src="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Hospital+Nurse+Staffing+-+Solver+Results.png" alt="Solver Results"/&gt;&#xD;
  &lt;/a&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           After just a moment, Solver displays a message that indicates that an optimal solution has been found that meets our constraints. Click "OK" and check to be sure the results are accurate.
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div&gt;&#xD;
  &lt;a&gt;&#xD;
    &lt;img src="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Hospital+Nurse+Staffing+with+Solver.png" alt="Optimized schedule"/&gt;&#xD;
  &lt;/a&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             ﻿
            
                        &#xD;
        &lt;/span&gt;&#xD;
        
                        
            The resulting schedule meets the staffing constraints for each 4-hour window, while minimizing the total number of nurses required. Now let's take a look at how this can be done in Python using
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;a href="https://github.com/coin-or/pulp" target="_blank"&gt;&#xD;
      
                      
           PuLP
          
                    &#xD;
    &lt;/a&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            . The first step is to install PuLP using the command
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           pip install pulp
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           .
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div&gt;&#xD;
  &lt;a&gt;&#xD;
    &lt;img src="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Hospital+Nurse+Staffing+-+pip+install+pulp.png" alt="pip install pulp"/&gt;&#xD;
  &lt;/a&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ﻿Here is some sample code, written in Python, that uses PuLP to solve this linear programming problem. We start by importing the pulp library, then setup a pulp.LpProblem object with a string description and the pulp.LpMinimize parameter to indicate that we want to minimize the number of staff. Next, we create variables to represent the number of nurses working each shift, then define the objective function by adding up the number of nurses for each shift. Finally, we add the six constraints to represent the minimum number of nurses for each 4-hour time window. For example, we need a minimum of 70 nurses for the first 4-hour time window from 6 - 10 a.m.
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            ﻿
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ''' Solving a staffing linear programming problem with PuLP in Python '''
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           import
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           pulp
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           prob = pulp.LpProblem(
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "Nurse Staffing"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           , pulp.LpMinimize)
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           # Variables to represent the number of nurses working each shift
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           shift1=pulp.LpVariable(
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "Shift1"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           0
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           None
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,pulp.LpInteger)
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           shift2=pulp.LpVariable(
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "Shift2"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           0
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           None
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,pulp.LpInteger)
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           shift3=pulp.LpVariable(
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "Shift3"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           0
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           None
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,pulp.LpInteger)
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           shift4=pulp.LpVariable(
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "Shift4"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           0
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           None
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,pulp.LpInteger)
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           shift5=pulp.LpVariable(
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "Shift5"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           0
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           None
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,pulp.LpInteger)
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           shift6=pulp.LpVariable(
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "Shift6"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           0
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           None
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,pulp.LpInteger)
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           # The objective function is added to 'prob' first
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           prob += shift1 + shift2 + shift3 + shift4 + shift5 + shift6, "Total Nurses"
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           # The six constraints to ensure there are enough nurses for each time period
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            prob += shift6 + shift1 &amp;gt;=
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           70
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "MimimumNurses06amTo10am"
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            prob += shift1 + shift2 &amp;gt;=
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           170
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "MimimumNurses10amTo2pm"
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            prob += shift2 + shift3 &amp;gt;=
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           200
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "MimimumNurses02pmTo6pm"
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            prob += shift3 + shift4 &amp;gt;=
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           85
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "MimimumNurses06pmTo10pm"
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            prob += shift4 + shift5 &amp;gt;=
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           25
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "MimimumNurses10pmTo2am"
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            prob += shift5 + shift6 &amp;gt;=
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           40
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           ,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "MimimumNurses02amTo06am"
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           # Solve the problem using PuLP's choice of Solver
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           prob.solve()
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           # The status of the solution is printed to the screen
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           print(
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "Status:"
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           , pulp.LpStatus[prob.status])
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           # Each of the variables is printed with it's resolved optimum value
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           for
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           v
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           in
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           prob.variables():
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
             print(v.name,
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "="
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           , v.varValue)
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           # The optimized objective function value is printed to the screen
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           print(
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           "Total number of nurses = "
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           , pulp.value(prob.objective))
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             ﻿
            
                        &#xD;
        &lt;/span&gt;&#xD;
        
                        
            Now, we are ready to solve using the LpProblem object's
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           solve()
          
                    &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            method, then print out the results of each variable.
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           Notice in the output show in figure 7 below that the number of nurses for each shift are different from those we found using Solver in Excel, but each of the constraints is met and the total, minimum number of nurses is the same: 295.
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            ﻿
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div&gt;&#xD;
  &lt;a&gt;&#xD;
    &lt;img src="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Hospital+Nurse+Staffing+-+PuLP+Results.png" alt="PuLP results"/&gt;&#xD;
  &lt;/a&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           Now we can validate the PuLP results by plugging the shift numbers into our Excel model as shown in Figure 8 below. Even though the 10 p.m. - 6 a.m. shift has 0 nurses, the 25 nurses who started during the previous shift from 6 p.m. - 2 a.m. are sufficient to ensure there are 25 nurses available during from 10 p.m. - 2 a.m.
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        
                        
            ﻿
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div&gt;&#xD;
  &lt;a&gt;&#xD;
    &lt;img src="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Hospital+Nurse+Staffing+-+checking+PuLP+results.png" alt="Checking PuLP results"/&gt;&#xD;
  &lt;/a&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;span&gt;&#xD;
        &lt;span&gt;&#xD;
          
                          
             ﻿
            
                        &#xD;
        &lt;/span&gt;&#xD;
        
                        
            In this Python example, we have seen how linear programming can help solve real world problems and how these can be solved in Python using PuLP. If you would like to try running this code sample,
           
                      &#xD;
      &lt;/span&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;a href="https://colab.research.google.com/drive/1sX6qjcvWbi8wpBI8DfZwz94xPKgR7kFv?usp=sharing" target="_blank"&gt;&#xD;
      
                      
           access it here
          
                    &#xD;
    &lt;/a&gt;&#xD;
    &lt;span&gt;&#xD;
      
                      
           .
          
                    &#xD;
    &lt;/span&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/p&gt;&#xD;
  &lt;p&gt;&#xD;
    
                    
          If you have any questions, please leave a comment below or contact us. We look forward to seeing how you use linear programming in Python to solve your real world challenges.
         
                  &#xD;
  &lt;/p&gt;&#xD;
&lt;/div&gt;</content:encoded>
      <enclosure url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/architecture-931283_1920.jpg" length="678137" type="image/jpeg" />
      <pubDate>Mon, 22 Jun 2020 06:29:11 GMT</pubDate>
      <guid>https://www.pythonstart.com/solving-linear-programming-problems-in-python-with-pulp</guid>
      <g-custom:tags type="string">Excel,Linear programming,Python,PuLP</g-custom:tags>
      <media:content medium="image" url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/architecture-931283_1920.jpg">
        <media:description>thumbnail</media:description>
      </media:content>
      <media:content medium="image" url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/architecture-931283_1920.jpg">
        <media:description>main image</media:description>
      </media:content>
    </item>
    <item>
      <title>The list of Python Packages is Massive</title>
      <link>https://www.pythonstart.com/the-list-of-python-packages-is-massive</link>
      <description>One of the key reasons for Python's success is its tremendous ecosystem. Learn more in this blog post.</description>
      <content:encoded>&lt;h3&gt;&#xD;
  
         Python's geometric rise is due, at least in part, to a tremendous list of packages
        &#xD;
&lt;/h3&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  
         Python has experienced tremendous recent adoption for
         &#xD;
  &lt;font&gt;&#xD;
    &lt;a href="https://pythonstart.com/getting-started-with-python" target="_blank"&gt;&#xD;
      
           at least 5 reasons
          &#xD;
    &lt;/a&gt;&#xD;
  &lt;/font&gt;&#xD;
  
         . One of those reasons is the vast set of available Python packages.
        &#xD;
&lt;/div&gt;&#xD;
&lt;h3&gt;&#xD;
  
         What is a Python Module?
        &#xD;
&lt;/h3&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  &lt;div&gt;&#xD;
    &lt;span&gt;&#xD;
      
           In order to understand
           &#xD;
      &lt;a href="https://docs.python.org/3/tutorial/modules.html#packages" target="_blank"&gt;&#xD;
        &lt;font&gt;&#xD;
          
             Python
             &#xD;
          &lt;i&gt;&#xD;
            
              packages
             &#xD;
          &lt;/i&gt;&#xD;
        &lt;/font&gt;&#xD;
      &lt;/a&gt;&#xD;
      
           , it's helpful to first understand
           &#xD;
      &lt;a href="https://docs.python.org/3/tutorial/modules.html#modules" target="_blank"&gt;&#xD;
        &lt;font&gt;&#xD;
          
             Python
             &#xD;
          &lt;i&gt;&#xD;
            
              modules
             &#xD;
          &lt;/i&gt;&#xD;
        &lt;/font&gt;&#xD;
      &lt;/a&gt;&#xD;
      
           . Modules are individual Python files that can be imported and interpreted at run-time. For example, you could create a file named 
           &#xD;
      &lt;i&gt;&#xD;
        
            log_search.py
           &#xD;
      &lt;/i&gt;&#xD;
      
           in the current directory and then import the module using the 
           &#xD;
      &lt;i&gt;&#xD;
        
            import
           &#xD;
      &lt;/i&gt;&#xD;
      
           command. You can then access the
           &#xD;
      &lt;i&gt;&#xD;
        
            log_search
           &#xD;
      &lt;/i&gt;&#xD;
      
            functions from your
           &#xD;
      &lt;i&gt;&#xD;
        
            main
           &#xD;
      &lt;/i&gt;&#xD;
      
            application module. We'll dive into modules and functions in more detail, but for now think of a module as a collection of definitions and statements that comprise a set of related capabilities. Each function within a module is accessed using the module name, followed by a period (.) like this:
          &#xD;
    &lt;/span&gt;&#xD;
  &lt;/div&gt;&#xD;
  &lt;div&gt;&#xD;
    &lt;span&gt;&#xD;
      &lt;br/&gt;&#xD;
    &lt;/span&gt;&#xD;
  &lt;/div&gt;&#xD;
  &lt;div&gt;&#xD;
    &lt;span&gt;&#xD;
      
           import log_search
          &#xD;
    &lt;/span&gt;&#xD;
  &lt;/div&gt;&#xD;
  &lt;div&gt;&#xD;
    &lt;span&gt;&#xD;
      
           log_search.find("pythonstart.com")
          &#xD;
    &lt;/span&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/div&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;h3&gt;&#xD;
  
         What is a Python Package?
        &#xD;
&lt;/h3&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  
         A package is a collection of Python modules. This lets you organize even larger sets of capabilities into a single package. For example, perhaps you want to create an
         &#xD;
  &lt;i&gt;&#xD;
    
          log_analysis
         &#xD;
  &lt;/i&gt;&#xD;
  
         package that includes many different sets of capabilities, and perhaps it will grow over time. Within this package, you want to include a set of functions that let users search log files (
         &#xD;
  &lt;i&gt;&#xD;
    
          log_search
         &#xD;
  &lt;/i&gt;&#xD;
  
         ) and a set of functions to append, split, and save log files, which you'll call (
         &#xD;
  &lt;i&gt;&#xD;
    
          log_file_ops
         &#xD;
  &lt;/i&gt;&#xD;
  
         ). Each module is a file that sits within a 
         &#xD;
  &lt;i&gt;&#xD;
    
          log_analysis
         &#xD;
  &lt;/i&gt;&#xD;
  
         folder. You can even nest packages, so that you can include multiple packages in a single
         &#xD;
  &lt;i&gt;&#xD;
    
          web_ops
         &#xD;
  &lt;/i&gt;&#xD;
  
          package. To do this, you simply create a top-level folder named
         &#xD;
  &lt;i&gt;&#xD;
    
          web_ops
         &#xD;
  &lt;/i&gt;&#xD;
  
         , add the 
         &#xD;
  &lt;i&gt;&#xD;
    
          log_analysis
         &#xD;
  &lt;/i&gt;&#xD;
  
         folder and create sibling folders such as 
         &#xD;
  &lt;i&gt;&#xD;
    
          web_server
         &#xD;
  &lt;/i&gt;&#xD;
  
         . Below is a view of the folder structure:
         &#xD;
  &lt;div&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/div&gt;&#xD;
  &lt;div&gt;&#xD;
    
          web_ops/                              Top-level package
         &#xD;
  &lt;/div&gt;&#xD;
  &lt;blockquote&gt;&#xD;
    &lt;div&gt;&#xD;
      
           __init__.py                    Initialize the web_ops package
          &#xD;
    &lt;/div&gt;&#xD;
    &lt;div&gt;&#xD;
      &lt;span&gt;&#xD;
        
            web_server/                 Subpackage for web server functionality      
           &#xD;
      &lt;/span&gt;&#xD;
    &lt;/div&gt;&#xD;
  &lt;/blockquote&gt;&#xD;
  &lt;blockquote&gt;&#xD;
    &lt;blockquote&gt;&#xD;
      &lt;div&gt;&#xD;
        &lt;span&gt;&#xD;
          
             __init__.py           Initialize the web_server package
            &#xD;
        &lt;/span&gt;&#xD;
      &lt;/div&gt;&#xD;
      &lt;div&gt;&#xD;
        &lt;span&gt;&#xD;
          
             deploy.py             Functions to deploy your web server
            &#xD;
        &lt;/span&gt;&#xD;
      &lt;/div&gt;&#xD;
      &lt;div&gt;&#xD;
        &lt;span&gt;&#xD;
          
             start.py                Functions to start your web server
            &#xD;
        &lt;/span&gt;&#xD;
      &lt;/div&gt;&#xD;
    &lt;/blockquote&gt;&#xD;
    &lt;span&gt;&#xD;
      
           log_analysis/               
          &#xD;
    &lt;/span&gt;&#xD;
    &lt;span&gt;&#xD;
      
           Subpackage for log analysis functionality
          &#xD;
    &lt;/span&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/blockquote&gt;&#xD;
  &lt;blockquote&gt;&#xD;
    &lt;blockquote&gt;&#xD;
      &lt;div&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;span&gt;&#xD;
            
              __init__.py         Initialize the log_analysis package
             &#xD;
          &lt;/span&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;span&gt;&#xD;
            
              log_search.py    Functions to search your logs
             &#xD;
          &lt;/span&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;div&gt;&#xD;
          &lt;span&gt;&#xD;
            
              log_file_ops
             &#xD;
          &lt;/span&gt;&#xD;
          &lt;span&gt;&#xD;
            
              .py   Functions to modify your log files
             &#xD;
          &lt;/span&gt;&#xD;
        &lt;/div&gt;&#xD;
      &lt;/div&gt;&#xD;
    &lt;/blockquote&gt;&#xD;
  &lt;/blockquote&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;h3&gt;&#xD;
  
         Popular Python Packages
        &#xD;
&lt;/h3&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  
         Below are a few popular Python packages as examples:
         &#xD;
  &lt;div&gt;&#xD;
    &lt;ul&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;a href="http://numpy.scipy.org/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              NumPy
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;a href="http://www.scipy.org/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              SciPy
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;a href="http://matplotlib.sourceforge.net/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              matplotlib
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;font&gt;&#xD;
          &lt;a href="http://www.nltk.org/" target="_blank"&gt;&#xD;
            
              nltk
             &#xD;
          &lt;/a&gt;&#xD;
        &lt;/font&gt;&#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;a href="http://www.pygame.org/news.html" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Pygame
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;a href="http://www.python-requests.org/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Requests
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;font&gt;&#xD;
          &lt;a href="http://www.scrapy.org/" target="_blank"&gt;&#xD;
            
              Scrapy
             &#xD;
          &lt;/a&gt;&#xD;
        &lt;/font&gt;&#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;a href="http://wxpython.org/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              wxPython
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;a href="https://github.com/python-imaging/Pillow" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Pillow
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;a href="http://www.sqlalchemy.org/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              SQLAlchemy
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;a href="http://www.crummy.com/software/BeautifulSoup/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              BeautifulSoup
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;font&gt;&#xD;
          &lt;a href="http://twistedmatrix.com/" target="_blank"&gt;&#xD;
            
              Twisted
             &#xD;
          &lt;/a&gt;&#xD;
        &lt;/font&gt;&#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;a href="http://www.pyglet.org/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Pyglet
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
      &lt;/li&gt;&#xD;
    &lt;/ul&gt;&#xD;
    &lt;blockquote&gt;&#xD;
      &lt;blockquote&gt;&#xD;
        &lt;div&gt;&#xD;
        &lt;/div&gt;&#xD;
      &lt;/blockquote&gt;&#xD;
    &lt;/blockquote&gt;&#xD;
  &lt;/div&gt;&#xD;
&lt;/div&gt;</content:encoded>
      <enclosure url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Python+packages-5846x4134.jpg" length="128149" type="image/jpeg" />
      <pubDate>Sat, 04 Mar 2017 08:00:00 GMT</pubDate>
      <author>info@pythonstart.com (Python Start)</author>
      <guid>https://www.pythonstart.com/the-list-of-python-packages-is-massive</guid>
      <g-custom:tags type="string">Python Packages,Packages,Python Modules,Python</g-custom:tags>
      <media:content medium="image" url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Python+packages-5846x4134.jpg">
        <media:description>thumbnail</media:description>
      </media:content>
      <media:content medium="image" url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Python+packages-5846x4134.jpg">
        <media:description>main image</media:description>
      </media:content>
    </item>
    <item>
      <title>7 Brilliant Python Examples You Should Know</title>
      <link>https://www.pythonstart.com/7-brilliant-python-examples-you-should-know</link>
      <description>Python is becoming a popular programming language, and here are 7 examples to prove it</description>
      <content:encoded>&lt;h3&gt;&#xD;
  
         Python is a powerhouse. Here are 7 real-world examples to prove it.
        &#xD;
&lt;/h3&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  
         Perhaps you have heard that Python is the programming language of choice for many developers, but perhaps you are wondering who really uses it and what they build with Python. Here are 7 examples of Python's impressive versatility:
         &#xD;
  &lt;div&gt;&#xD;
    &lt;ol&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;b&gt;&#xD;
          
             Pinterest
            &#xD;
        &lt;/b&gt;&#xD;
        
            - Now a social media magnet,
            &#xD;
        &lt;a href="http://venturebeat.com/2017/02/10/pinterest-hires-google-image-search-vet-as-its-first-search-chief/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              attracting Google Execs
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            , Pinterest's
            &#xD;
        &lt;a href="http://www.businessinsider.com/inside-pinterest-an-overnight-success-four-years-in-the-making-2012-4" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              humble start
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            is rooted in Python. "When we first started building Pinterest, we used Python as our development language, which helped us build quickly and reliably. Over the years we built many tools around Python, including Pinball, MySQL_utils and pymemcache, as well as a set of libraries used daily for service communication and configuration management." - 
            &#xD;
        &lt;a href="https://medium.com/@Pinterest_Engineering/open-sourcing-kingpin-building-blocks-for-scaling-pinterest-8febe81f2c1c" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Shu Zhang
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            , Pinterest engineer, Infrastructure (
            &#xD;
        &lt;a href="https://medium.com/@Pinterest_Engineering/open-sourcing-kingpin-building-blocks-for-scaling-pinterest-8febe81f2c1c" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Medium
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            )
           &#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;b&gt;&#xD;
          
             YouTube
            &#xD;
        &lt;/b&gt;&#xD;
        
            - YouTube has grown to become a household name and "its most famous star,
            &#xD;
        &lt;a href="https://www.forbes.com/pictures/gjdm45ffed/1-pewdiepie/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              PewDiePie
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            , makes approximately $15 million a year through his following of more than 50 million, according to Forbes." (
            &#xD;
        &lt;a href="http://www.kansas.com/entertainment/ent-columns-blogs/keeper-of-the-plans/article134642209.html" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              The Witchita Eagle
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            ) "Python is fast enough for our site and allows us to produce maintainable features in record times, with a minimum of developers." - Cuong Do, Software Architect,
            &#xD;
        &lt;a href="https://www.youtube.com" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              YouTube.com
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
             (
            &#xD;
        &lt;a href="https://www.python.org/about/quotes/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Python.org
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            )
           &#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;b&gt;&#xD;
          
             NASA
            &#xD;
        &lt;/b&gt;&#xD;
        
            - The
            &#xD;
        &lt;a href="https://wiki.python.org/moin/TkInter" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              TkInter
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
             module is a 
            &#xD;
        &lt;a href="https://wiki.python.org/moin/TkInter" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Graphical User Interface (GUI) toolkit for Python
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            . TkInter was used extensively in NASA's Workflow Automation System (WAS). "Python allows us to tackle the complexity of programs like the WAS without getting bogged down in the language." - Robin Friedrich, Senior Project Engineer,
            &#xD;
        &lt;a href="http://www.unitedspacealliance.com/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              United Space Alliance
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
             -- NASA's main shuttle support contractor. (
            &#xD;
        &lt;a href="https://www.python.org/about/success/usa/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Python.org
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            )
           &#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;b&gt;&#xD;
          
             Industrial Light &amp;amp; Magic
            &#xD;
        &lt;/b&gt;&#xD;
        
            (Lucasfilm, Walt Disney) - ILM has
            &#xD;
        &lt;a href="https://www.wired.com/2015/05/inside-ilm/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              forumlated billions of lines of code to support 300+ movies
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
             and Rogue One
            &#xD;
        &lt;a href="http://www.theverge.com/2017/2/19/14660488/rogue-one-vfx-ilm-reel-watch-scarif-x-wing-battle" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              recently earned an Oscar nomination
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            for its special effects. "Python plays a key role in our production pipeline. Without it a project the size of Star Wars: Episode II would have been very difficult to pull off. From crowd rendering to batch processing to compositing, Python binds all things together." - Tommy Burnette, Senior Technical Director,
            &#xD;
        &lt;a href="http://www.ilm.com/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Industrial Light &amp;amp; Magic
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            . (
            &#xD;
        &lt;a href="https://www.python.org/about/quotes/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Python.org
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            )
           &#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;b&gt;&#xD;
          
             Dropbox
            &#xD;
        &lt;/b&gt;&#xD;
        
            - Dropbox now has over half a billion users around the world. via 
            &#xD;
        &lt;a href="https://blogs.dropbox.com/dropbox/2016/03/500-million/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Dropbox blog
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
             "[Python has] helped [Dropbox] stay lean and the product remain simple as it [scaled] to let over 100 million users save over 1 billion files per day." (
            &#xD;
        &lt;a href="https://techcrunch.com/2012/12/07/dropbox-guido-van-rossum-python/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              TechCrunch
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            )
           &#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;b&gt;&#xD;
          
             Google
            &#xD;
        &lt;/b&gt;&#xD;
        
            - "Python has been an important part of Google since the beginning, and remains so as the system grows and evolves. Today dozens of Google engineers use Python, and we're looking for more people with skills in this language." - Peter Norvig, director of search quality at Google, Inc. (
            &#xD;
        &lt;a href="https://www.python.org/about/quotes/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Python.org
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            )
           &#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        &lt;b&gt;&#xD;
          
             EA Games
            &#xD;
        &lt;/b&gt;&#xD;
        
             (Electronic Arts) - One of the reasons
            &#xD;
        &lt;a href="https://en.wikipedia.org/wiki/Battlefield_2" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Battlefield 2 remained so popular
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            , was its support for mods written in Python (
            &#xD;
        &lt;a href="http://www.fz.se/artiklar/intervju/20050210/dice-in-reply-to-your-questions-regarding-battlefield-2/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              FZ
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            ). Python has been used by game developers as early as
            &#xD;
        &lt;a href="https://en.wikipedia.org/wiki/Earth_%26_Beyond" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Earth &amp;amp; Beyond
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            . (Sean Riley's
            &#xD;
        &lt;font&gt;&#xD;
          &lt;a href="https://www.amazon.com/gp/product/1584502584/?creativeASIN=1584502584&amp;amp;tag=pythonstart-20" target="_blank"&gt;&#xD;
            
              Game Programming With Python
             &#xD;
          &lt;/a&gt;&#xD;
        &lt;/font&gt;&#xD;
        
            ) 
           &#xD;
      &lt;/li&gt;&#xD;
    &lt;/ol&gt;&#xD;
    &lt;span&gt;&#xD;
      
           Do you know of other noteworthy Python examples? Please tweet them to us at
           &#xD;
      &lt;font&gt;&#xD;
        &lt;a href="https://twitter.com/StartPython" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              @StartPython
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        &lt;font&gt;&#xD;
          
             .
            &#xD;
        &lt;/font&gt;&#xD;
      &lt;/font&gt;&#xD;
    &lt;/span&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/div&gt;&#xD;
&lt;/div&gt;</content:encoded>
      <enclosure url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Python+examples-7680x4320.jpeg" length="462068" type="image/jpeg" />
      <pubDate>Sat, 25 Feb 2017 08:00:00 GMT</pubDate>
      <author>info@pythonstart.com (Python Start)</author>
      <guid>https://www.pythonstart.com/7-brilliant-python-examples-you-should-know</guid>
      <g-custom:tags type="string">deep learning,machine learning,programming,Python</g-custom:tags>
      <media:content medium="image" url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Python+examples-7680x4320.jpeg">
        <media:description>thumbnail</media:description>
      </media:content>
      <media:content medium="image" url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Python+examples-7680x4320.jpeg">
        <media:description>main image</media:description>
      </media:content>
    </item>
    <item>
      <title>Getting Started with Python</title>
      <link>https://www.pythonstart.com/getting-started-with-python</link>
      <description>Learn why Python is such a popular programming language</description>
      <content:encoded>&lt;h3&gt;&#xD;
  
         Learning Python for APIs, analysis, automation, and deep learning
        &#xD;
&lt;/h3&gt;&#xD;
&lt;div data-rss-type="text"&gt;&#xD;
  
         Python is growing in popularity and is currently listed among the top 5 programming languages in the
         &#xD;
  &lt;a href="http://www.tiobe.com/tiobe-index/" target="_blank"&gt;&#xD;
    &lt;font&gt;&#xD;
      
           TIOBE Index
          &#xD;
    &lt;/font&gt;&#xD;
  &lt;/a&gt;&#xD;
  
         . Why is Python so popular? Below are 5 reasons:
         &#xD;
  &lt;div&gt;&#xD;
    &lt;ol&gt;&#xD;
      &lt;li&gt;&#xD;
        
            Libraries - many popular and supported libraries (e.g., 
            &#xD;
        &lt;a href="https://docs.python.org/3/library/asyncio.html" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              asyncio
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            ,
            &#xD;
        &lt;a href="http://matplotlib.org/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              matplotlib
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            ,
            &#xD;
        &lt;a href="http://www.scipy.org/install.html" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              numpy
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            )
           &#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        
            Easy to learn - 
            &#xD;
        &lt;a href="https://talkpython.fm/episodes/show/100/python-past-present-and-future-with-guido-van-rossum" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              Guido van Rossum
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
        
            created Python based on his experience with its precursor,
            &#xD;
        &lt;a href="https://en.wikipedia.org/wiki/ABC_(programming_language)" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              ABC
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        
            Highly portable - Python is interpreted, so there's no need to compile binaries for every platform
           &#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        
            Popularity for analytics - Python is seeing growing use for
            &#xD;
        &lt;a href="http://r4stats.com/2015/03/30/fastest-growing-analytics-2015/" target="_blank"&gt;&#xD;
          
             scholarly analytics
            &#xD;
        &lt;/a&gt;&#xD;
      &lt;/li&gt;&#xD;
      &lt;li&gt;&#xD;
        
            Readily available - you can download the
            &#xD;
        &lt;a href="https://www.python.org/downloads/" target="_blank"&gt;&#xD;
          &lt;font&gt;&#xD;
            
              latest version of Python for free
             &#xD;
          &lt;/font&gt;&#xD;
        &lt;/a&gt;&#xD;
      &lt;/li&gt;&#xD;
    &lt;/ol&gt;&#xD;
    &lt;span&gt;&#xD;
      
           This blog is designed to help you get started learning Python for fun and for profit!
          &#xD;
    &lt;/span&gt;&#xD;
    &lt;br/&gt;&#xD;
  &lt;/div&gt;&#xD;
&lt;/div&gt;</content:encoded>
      <enclosure url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Laptop-hands-computer_1142_831_d.jpg" length="253040" type="image/jpeg" />
      <pubDate>Thu, 23 Feb 2017 08:00:00 GMT</pubDate>
      <author>info@pythonstart.com (Python Start)</author>
      <guid>https://www.pythonstart.com/getting-started-with-python</guid>
      <g-custom:tags type="string">Python</g-custom:tags>
      <media:content medium="image" url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Laptop-hands-computer_1142_831_d.jpg">
        <media:description>thumbnail</media:description>
      </media:content>
      <media:content medium="image" url="https://irp-cdn.multiscreensite.com/3d1ca157/dms3rep/multi/Laptop-hands-computer_1142_831_d.jpg">
        <media:description>main image</media:description>
      </media:content>
    </item>
  </channel>
</rss>
