Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create a function without split in python

I’m trying to create a function for agrupation 6 to 6 letters of a sentence, but without use split function.

My code is:

test="the world is mine today" 

def agru_letters(phrase):
    data = [] 
    for i in range(len(phrase) - 5):
        data.append(phrase[i:i+6])

print(agru_letters(phrase))

and the output that I want is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

['thewor',
 'heworl',
 'eworld',
 'worldi',
 'orldis',
 'rldism',
 'ldismi',
 'dismin',
 'ismine',
 'sminet',
 'mineto',
 'inetod',
 'netoda',
 'etoday']

>Solution :

Not sure if this is what you’re expecting

test="the world is mine today" 

def agru_letters(phrase):
    data = []
    new = phrase.replace(' ', '')
    for i in range(len(new) - 5):
        data.append(new[i:i+6])
    return data
agru_letters(test)

Output:

['thewor',
 'heworl',
 'eworld',
 'worldi',
 'orldis',
 'rldism',
 'ldismi',
 'dismin',
 'ismine',
 'sminet',
 'mineto',
 'inetod',
 'netoda',
 'etoday']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading