Ask Your Question

var list with only one variable error

asked 2019-08-14 09:00:37 +0200

ortollj gravatar image

updated 2023-01-09 23:59:51 +0200

tmonteil gravatar image


SageMath 8.8 notebook OS=W10

why does it fail if L has only one variable ? :

edit retag flag offensive close merge delete


FWIW, when I run var(['x']) I get TypeError: unhashable type 'list'. Is this what you got? When reporting on a behavior please describe exactly the behavior you observed, and the behavior you expected instead.

Iguananaut gravatar imageIguananaut ( 2019-08-14 12:44:46 +0200 )edit

In any case, whether or not you got what I did, there seems to be a bug here in the treatment of var() on a single-item list or tuple.

Iguananaut gravatar imageIguananaut ( 2019-08-14 12:59:25 +0200 )edit

yes TypeError: unhashable type 'list' was the error I got

to avoid this error I did this little workaround:

if len(rL)==1 :
else :
ortollj gravatar imageortollj ( 2019-08-14 14:06:15 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-08-14 14:14:14 +0200

Iguananaut gravatar image

updated 2019-08-14 14:15:02 +0200

It seems for now you'll have to do an ugly workaround like:

sage: var(L[0] if len(L) == 1 else L)

I have opened a ticket with a proposed fix to the bug:

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-08-14 09:00:37 +0200

Seen: 270 times

Last updated: Aug 14 '19