0

for example i have a list

mylist=[[1,2],[5,8],[-9,2],[0,-9],[4,0],[0,-4],[-1,-1]]

to remove [-9,2] is by

mylist.remove([-9,2])

i want to use .remove() by using the value of list[2] which is equal to [-9,2] like this

 mylist.remove(list[2])

but it will give a none value is there any alternative to this because i am looping the value of the index >> list[value changing per loop]. how can i solve this?

this is the loop

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)
LOURD
  • 1
  • 1
  • 2

2 Answers2

0

What you are looking for is probably list.pop(2) since it removes a list element at a given index.

You could also use the del statement, here is the official doc of it: https://docs.python.org/3/tutorial/datastructures.html#the-del-statement

Lone Lunatic
  • 805
  • 8
  • 20
0

You need

templist=mylist.pop(p)

instead of

templist=mylist.remove(mylist[p])

Next time, please copy-paste the complete relevant code.

Saurav Sahu
  • 13,038
  • 6
  • 64
  • 79