Skip to content

Instantly share code, notes, and snippets.

@ishank-dev
Last active March 26, 2020 08:06
Show Gist options
  • Save ishank-dev/d839dab71710049061f6ae37cae0cb18 to your computer and use it in GitHub Desktop.
Save ishank-dev/d839dab71710049061f6ae37cae0cb18 to your computer and use it in GitHub Desktop.
'''
'A' and 'I' are the only one letter word present in english language,
hence this algorithm concatenates the other single letters with the
next word in case they are anything other than 'A' or 'I'.
'''
def test(text):
list_words = text.split()
if len(list_words[0])==1:
if list_words[0] not in ['A','I']:
list_words[1] = list_words[0] + list_words[1]
list_words.pop(0)
updated_text = ' '
updated_text = updated_text.join(list_words)
print(updated_text)
string = "W HEN they met at the house of the police"
string_one = "I am a boy"
string_two = "When I was young"
test(string)
test(string_one)
test(string_two)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment