# remove list element from a list of list with symbolic pi

HI

I'm reporting something that seems odd to me.

I want to remove from a list of lists an element which is itself a list. if I convert the elements to string before comparing them the two lists are equivalent, but if I don't do the string conversion, then SageMath finds a difference between the two lists. equiv which was written by hand is ok, we can remove an element from this list, while the one made by Arrangement does not allow this element to be removed without first having it converted to a string.

upAndRightSidesL=[[2*pi, 2*pi], [0, 2*pi], [pi, 2*pi], [3/2*pi, 2*pi], [1/2*pi, 2*pi], [2*pi, pi],
[2*pi, 0], [2*pi, 3/2*pi], [2*pi, 1/2*pi]]
equiv=[[2*pi, 2*pi], [2*pi, 0], [0, 2*pi], [0, 0]]
print('equiv not build by Arrangements: ', equiv)

## if these 3 lines are not commented then [2*pi, 2*pi] is not removed in newL
#for pt in upAndRightSidesL :
#    if pt[0]==2*pi and pt[1] ==2*pi:
#        equiv=Arrangements( [pt[0]] + [0] + [pt[0]] + [0]   ,2).list()

print('upAndRightSidesL : ', upAndRightSidesL)
print('equiv build by Arrangement : ', equiv)

print(upAndRightSidesL)
def removeFromList(el,L) :
newL=[]
for index in range(len(L)) :
#if str(el) != str(L[index]) : # if string conversion beforehand then both list are ok
if el != L[index] :
newL.append(L[index])
else :
print ('not included',str(el))
return newL

newL=removeFromList(equiv[0],upAndRightSidesL)

show('newL : ',newL)

edit retag close merge delete

oops I forgot to write this precision for versions !!.

W11 WSL UBUNTU 22.04 SageMath 9.8

( 2023-03-04 11:54:13 +0200 )edit

Sort by ยป oldest newest most voted

The reason for the observed behavior is that the elements of Arrangements are not lists but

<class 'sage.combinat.permutation.Arrangements_msetk_with_category.element_class'>


and so they cannot be equal to lists even if the content is the same.

A simple fix is to perform conversion into a list in the removal call:

newL=removeFromList(list(equiv[0]),upAndRightSidesL)


Btw, your removeFromList function is an overkill - it can be done in a single line using list comprehension:

def removeFromList(el,L) :
return [e for e in L if e!=el]

more

Thank you @Max Alekseyev.

I had not suspected for a second that the function :

Arrangements( [pt[0]] + [0] + [pt[0]] + [0]   ,2).list()


does not return a true list !!

( 2023-03-04 17:22:06 +0200 )edit

It returns a list of Arragements elements.

( 2023-03-04 17:34:26 +0200 )edit

Oops ok , sorry.

( 2023-03-04 17:57:49 +0200 )edit