OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to write my own split function without using .split and .strip function?

  • Thread starter Thread starter An Yan
  • Start date Start date
A

An Yan

Guest
How to write my own split function? I just think I should remove spaces, '\t' and '\n'. But because of the shortage of knowledge, I have no idea of doing this question

Here is the original question:

Write a function split(string) that returns a list of words in the given string. Words may be separated by one or more spaces ' ' , tabs '\t' or newline characters '\n' .

And there are examples:

Code:
words = split('duff_beer 4.00') # ['duff_beer', '4.00']
words = split('a b c\n') # ['a', 'b', 'c']
words = split('\tx y \n z ') # ['x', 'y', 'z']

Restrictions: Don't use the str.split method! Don't use the str.strip method
<p>How to write my own split function? I just think I should remove spaces, <code>'\t'</code> and <code>'\n'</code>. But because of the shortage of knowledge, I have no idea of doing this question</p>

<p>Here is the original question:</p>

<blockquote>
<p>Write a function split(string) that returns a list of words in the
given string. Words may be separated by one or more spaces <code>' '</code> , tabs
<code>'\t'</code> or newline characters <code>'\n'</code> .</p>

<p>And there are examples:</p>

<pre><code>words = split('duff_beer 4.00') # ['duff_beer', '4.00']
words = split('a b c\n') # ['a', 'b', 'c']
words = split('\tx y \n z ') # ['x', 'y', 'z']
</code></pre>

<p>Restrictions: Don't use the <code>str.split</code> method! Don't use the <code>str.strip</code> method</p>
</blockquote>
 

Latest posts

M
Replies
0
Views
1
MusicLovingIndianGirl
M
Q
Replies
0
Views
1
quora question
Q
Top