Dividing a string

Question:

I have a list, i want to split the every string from "And" and join it to first action.

OLD_Txt=
["User enters validusername "MAXI" And password "768"",
"User enters phonenumber "76567898" And ZIPcode "97656"",
"User Verifys Country  "ENGLAND" And City "LONDON""]

I want my list look like this

New_Txt:

["User enters validusername "MAXI"", 
"User enters password "768"",
"User enters phonenumber "76567898"",
"User enters ZIPcode "97656"",
"User Verifys Country "ENGLAND"",
"User Verifys City "LONDON""]
Asked By: soumya panigrahi

||

Answers:

If I understood you corectly, you want to join your strings.
So you really want to:

New_Txt = ' '.join(OLD_Txt)
Answered By: GuyO
OLD_Txt= [
    'User enters validusername "MAXI" And password "768"', 
    'User enters phonenumber "76567898" And ZIPcode "97656"', 
    'User Verifys Country "ENGLAND" And City "LONDON"']

base_word = 'User '

new_text = []
for string_obj in OLD_Txt:
    first_part, second_part = string_obj.split('And')
    verb_for_second_part = first_part.split(' ')[1] 
    # from split you ll get ["User" "enters", "validusername", "MAXI"]
    # and you need text at index 1 i.e: verb_at_index
    new_text.append(first_part)

    second_part = base_word + verb_for_second_part + second_part
    new_text.append(second_part)

print(new_text)

output

['User enters validusername "MAXI" ', 'User enters password "768"', 'User enters phonenumber "76567898" ', 'User enters ZIPcode "97656"', 'User Verifys Country "ENGLAND" ', 'User Verifys City "LONDON"']
Answered By: shivankgtm
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.