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:
['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']