首页 > 解决方案 > 如何在不使用内置函数的情况下从python中的数组中删除元素

问题描述

如何在不使用python内置函数的情况下删除数组中的元素

我已经用内置函数尝试过这个程序,但没有它们我不知道怎么做

c = [6,7,8,9]
c.remove(c[0])
print(c)

我得到了预期的结果,但我想要它而不使用 python 中的内置函数。

标签: python

解决方案


这应该可以,但是此方法会创建一个新数组

c=[6,7,8,9]
d=[]
a=0
for x in c:
   if x!=c[a]: #or you write c[0] and remove the a=0
      d.append(x)

print(d) 

推荐阅读