I have a problem with python It is really easy but I still can find a solution for that:
I have a string. I split it. I have a for cycle
string = "Super best good string"
temp = string.split()
for finished_string in temp:
number = 0
finished_string.append(temp[number])
number = 1
The out of this should be: "Super best good string "
but This solution must be good for a different length of string with 2 words or 3 words
CodePudding user response:
string = "Super best good string"
temp = string.split()
new_string = ""
for finished_string in temp:
new_string = finished_string " "
CodePudding user response:
This code doesn't work for a few reasons, like finished_string.append(temp[number]) is appending something to itself in effect.
Instead use this:
string = "Super best good string"
finished_string = " ".join(string.split()) " "
print(finished_string)
