+ 1
a little problem
17 Réponses
+ 10
a solution, that does not need a list and is using replace() with a reverse range:
https://code.sololearn.com/cNH4cQFbwj6r/?ref=app
+ 6
https://code.sololearn.com/cOi76xbc881u/?ref=app
+ 5
solution that should meet the requirements of the post. it uses compress() function from itertools:
https://code.sololearn.com/cdfrGf7Hv8Tz/?ref=app
+ 3
Knight
Using another variable
str1 = ''
for i in range(len(list1)):
#print (list1 [i])
if list1[i] == ' ' and list1[i - 1] != ' ':
str1 += list1[i]
elif list1[i] != ' ':
str1 += list1[i]
print(str1)
https://code.sololearn.com/crvxnO2jrxV3/?ref=app
+ 2
Knight
You can remove within a range at once but on different indexes I don't think we can do at once
+ 2
The most efficient way to do it is probably regex pattern substitution.
https://pynative.com/JUMP_LINK__&&__python__&&__JUMP_LINK-regex-replace-re-sub/#h-substitute-multiple-whitespaces-with-single-whitespace-using-regex
+ 2
One liner:
https://code.sololearn.com/cQ48nTIr8Cvy/?ref=app
Edit: I see the problem has been changed to not allow split() as well (previously just didn't allow join). So this solution no longer qualifies
+ 2
Check the sololearn idea from the coach repos. KEEP PRACTICING
+ 1
Your method was better
thank you so much 🙏
however do u know how to remove several items in a list useing their indexes alltogether and instantly not one by one?
a method or atrib...
A͢J
+ 1
yes I know... I've converted the sentence to a list
Simon Sauter
+ 1
three methods 👌
big like👍
Oma Falk
+ 1
thanks Lothar 🙏
love ur code👌
+ 1
i think my code is more easy to understand
https://code.sololearn.com/cV36ADo9WTWk/?ref=app
+ 1
Ok. I think this meets the criteria, but not quite a one-liner
https://code.sololearn.com/c83SQXUlbn2W/?ref=app
0
Strings are immutable. What you're trying to do cannot be done like this.