Go to the link below and plz tell me what happened.in the code ? Plz😥😥😥😥 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Go to the link below and plz tell me what happened.in the code ? Plz😥😥😥😥

https://code.sololearn.com/c43rjbV88tvL/?ref=app

20th Feb 2022, 12:53 PM
Ḿɾ Ẵǩắśħ
Ḿɾ Ẵǩắśħ - avatar
4 Answers
+ 2
You shouldn't directly modify an iterable while iterating through it. Instead, you can create a new iterable and add items to it using a condition. The function should also consider index. Don't add a space even if the first char were in uppercase. A space is to be added only for successive uppercase chars. def add_space( string ): # <- use descriptive function name string = string.strip() # trim spaces ret = [ string[ 0 ] ] # first char not counted for # no need for space there even if it's uppercase for i in range( 1, len( string ) ): if string[ i ].isupper(): ret.extend( ( ' ', string[ i ] ) ) # add one space and the char else: ret.append( string[ i ] ) # just add the char return "".join( ret ) # glue list elements into string test_string = "InformationShouldBeFree" print( add_space( test_string ) )
20th Feb 2022, 2:11 PM
Ipang
+ 4
Your code is producing and infinite loop as you keep appending to the list that you are iterating. What is it supposed to do?
20th Feb 2022, 12:57 PM
Lisa
Lisa - avatar
+ 3
Again: WHAT IS IT SUPPOSED TO DO?
20th Feb 2022, 1:00 PM
Lisa
Lisa - avatar
+ 1
Then what I should do ...plz tell me...
20th Feb 2022, 12:58 PM
Ḿɾ Ẵǩắśħ
Ḿɾ Ẵǩắśħ - avatar