Go to the link below and plz tell me what happened.in the code ? Plz😥😥😥😥
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 ) )
Your code is producing and infinite loop as you keep appending to the list that you are iterating. What is it supposed to do?
Again: WHAT IS IT SUPPOSED TO DO?
Then what I should do ...plz tell me...