<?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>Forem: Akshat</title>
    <description>The latest articles on Forem by Akshat (@alexey_27).</description>
    <link>https://forem.com/alexey_27</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%2F1234797%2F97a8c3f4-2cd5-403e-b83d-96c49f80dcdb.jpg</url>
      <title>Forem: Akshat</title>
      <link>https://forem.com/alexey_27</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/alexey_27"/>
    <language>en</language>
    <item>
      <title>alternate way of doing word split/phrase segmentation in python</title>
      <dc:creator>Akshat</dc:creator>
      <pubDate>Wed, 26 Jun 2024 15:43:46 +0000</pubDate>
      <link>https://forem.com/alexey_27/alternate-way-of-doing-word-splitphrase-segmentation-in-python-pj1</link>
      <guid>https://forem.com/alexey_27/alternate-way-of-doing-word-splitphrase-segmentation-in-python-pj1</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Doing&lt;/strong&gt; word split with recursion felt a bit complex to me , so I tried to do it in an easier way.
&lt;/h2&gt;







&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5z5h5e8bxf0ng47kufhm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5z5h5e8bxf0ng47kufhm.png" alt="Image description" width="488" height="272"&gt;&lt;/a&gt; &lt;/p&gt;







&lt;ul&gt;
&lt;li&gt;The Hard Way (recursion) --
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
def word_split(phrase,list_of_words, output = None):

    if output is None:    #Base Case / Initial call
        output = []


    for word in list_of_words:        


        if phrase.startswith(word):                       

            output.append(word)

            return word_split(phrase[len(word):],list_of_words,output)    # Recursive Call


    return output        # Result

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;gives&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6238nl02e56j0os8v7cr.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6238nl02e56j0os8v7cr.PNG" alt="Image description" width="800" height="223"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;The Easy Way (indexing/for loop) -
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def word_split_2(phrase, word_list):
    output = []

    for i in word_list:
        if i in phrase:
            output.append(i)

    return output


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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0o0ymz8428wo8f7yjoc7.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0o0ymz8428wo8f7yjoc7.PNG" alt="Image description" width="800" height="116"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  this approach might be wrong , please correct me if it is
&lt;/h1&gt;

</description>
      <category>algorithms</category>
      <category>recursion</category>
      <category>python</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
