例如,我有一个列表
mylist=[[1,2],[5,8],[-9,2],[0,-9],[4,0],[0,-4],[-1,-1]]
删除[-9,2]是通过
mylist.remove([-9,2])
我想通过使用list[2]的值来使用.remove(),该值等于[-9,2],如下所示
mylist.remove(list[2])
但是它会给出一个none值,因为我正在循环索引的值>;>;list[每个循环的值变化],所以是否有其他方法可以替代它。我怎样才能解决这个问题?你知道吗
这是循环
for p in range (len(mylist)):
if mylist[p]==startpoint:
continue
if mylist[p]==nextpoint:
continue
thirdpoint=mylist[p]
print ('the thirdpoint is:',thirdpoint)
if orient(startpoint[0],startpoint[1],nextpoint[0],nextpoint[1],thirdpoint[0],thirdpoint[1])>0:
print ('ok')
print(mylist)
print ('the thirdpoint is:',thirdpoint)
templist=mylist.remove(mylist[p])
print ('templist is',templist)
if len(templist)==2:
print('append nextpoint:',nextpoint)
ppoint.append(nextpoint)
您要查找的可能是
list.pop(2)
,因为它删除了给定索引处的列表元素。你知道吗您也可以使用
del
语句,下面是它的官方文档:https://docs.python.org/3/tutorial/datastructures.html#the-del-statement你需要
而不是
下次请复制粘贴完整的相关代码。你知道吗
相关问题 更多 >
编程相关推荐