list1 = ["apple", "pear", "", "strawberry", "orange", "grapes", "", "watermelon"]
list2 = []
x = 0
while x < len(list1):
if len(list1[x]) > 0:
list2.append(list1[x])
print(list2)
Run Code Online (Sandbox Code Playgroud)
我尝试运行这段代码,但似乎不起作用。我应该如何不使用列表理解或其他方法来修改此代码?