26th Mar 2022, 4:49 PM
Salimi
Salimi - avatar
17 ответов
+ 10
a solution, that does not need a list and is using replace() with a reverse range: https://code.sololearn.com/cNH4cQFbwj6r/?ref=app
26th Mar 2022, 7:27 PM
Lothar
Lothar - avatar
+ 6
https://code.sololearn.com/cOi76xbc881u/?ref=app
26th Mar 2022, 6:25 PM
Oma Falk
Oma Falk - avatar
+ 5
solution that should meet the requirements of the post. it uses compress() function from itertools: https://code.sololearn.com/cdfrGf7Hv8Tz/?ref=app
28th Mar 2022, 11:04 AM
Lothar
Lothar - avatar
+ 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
26th Mar 2022, 5:14 PM
A͢J
A͢J - avatar
+ 2
Knight You can remove within a range at once but on different indexes I don't think we can do at once
26th Mar 2022, 5:54 PM
A͢J
A͢J - avatar
26th Mar 2022, 6:12 PM
Simon Sauter
Simon Sauter - avatar
+ 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
27th Mar 2022, 7:54 AM
Steve
Steve - avatar
+ 2
Steve Python magic.😎Thumbs up. I was going for print((' '). join(sentence.split())) but your print(*sentence.split()) was just better.
27th Mar 2022, 5:15 PM
Bob_Li
Bob_Li - avatar
27th Mar 2022, 9:04 PM
V_brawl
V_brawl - avatar
+ 2
Check the sololearn idea from the coach repos. KEEP PRACTICING
28th Mar 2022, 12:14 PM
FlashCoder
FlashCoder - avatar
+ 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
26th Mar 2022, 5:47 PM
Salimi
Salimi - avatar
+ 1
yes I know... I've converted the sentence to a list Simon Sauter
26th Mar 2022, 5:49 PM
Salimi
Salimi - avatar
+ 1
three methods 👌 big like👍 Oma Falk
26th Mar 2022, 10:32 PM
Salimi
Salimi - avatar
+ 1
thanks Lothar 🙏 love ur code👌
26th Mar 2022, 10:33 PM
Salimi
Salimi - avatar
+ 1
i think my code is more easy to understand https://code.sololearn.com/cV36ADo9WTWk/?ref=app
27th Mar 2022, 5:42 PM
😎_M_😎
😎_M_😎 - avatar
+ 1
Ok. I think this meets the criteria, but not quite a one-liner https://code.sololearn.com/c83SQXUlbn2W/?ref=app
27th Mar 2022, 7:22 PM
Steve
Steve - avatar
0
Strings are immutable. What you're trying to do cannot be done like this.
26th Mar 2022, 5:03 PM
Simon Sauter
Simon Sauter - avatar