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'
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)
+ 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)
+ 1
👍
0
Thanks