0

To remove empty character from string

words = ["abc d e h ghjj"] h = 0 g = 0 v=len(words[0]) new_words = [0][0] print (words[0][0]) while h <= v-1: if words[0][h] != " ": new_words[0][g] = (words[0][h]) g=g+1 h = h+1 print(new_words) Out put showing error "int object is not subscriptable'

31st May 2020, 11:01 AM
chetan bhagat
chetan bhagat - avatar
4 ответов
+ 1
It doesn't works the way you are doing ,you can do something like this words = ["abc d e h ghjj"] h =0 v=len(words[0]) new_words = "" print (words[0][0]) while h <= v-1: if words[0][h] != " ": new_words+=words[0][h] h = h+1 list=[] print(list.append(new_words)) print(list)
31st May 2020, 11:29 AM
Abhay
Abhay - avatar
+ 1
new_words=[0][0] print(type(new_words)) """new_words[0][0]=1""" #wrong way """print(new_words)""" new_words=[[None]] #right way new_words[0][0]=1 print(new_words)
31st May 2020, 11:34 AM
Abhay
Abhay - avatar
+ 1
👍
31st May 2020, 11:49 AM
Abhay
Abhay - avatar
0
Thanks
31st May 2020, 11:48 AM
chetan bhagat
chetan bhagat - avatar