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"]
CodePudding user response:
If you understood you corectly, you want to join your strings. So you really want to:
New_Txt = ' '.join(OLD_Txt)
CodePudding user response:
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"']