Ask Your Question
0

Calling the length of a list of inequality strings result in an error

asked 2022-03-29 11:24:34 +0100

Cyrille gravatar image

I wonder if this is a bug

sign=['>=', '<=', '=']
m1=[1 if (v=="<=" or v==">=") else 2 for v in sign]
m1

The len(m1) is defined but

y=var('y_',n=range(len(m1)))

return the error '>' not supported between instances of 'range' and 'int'

edit retag flag offensive close merge delete

Comments

Note that len(m1) will be the same as len(sign). Do you want the length of m1 or the number of distinct elements or the actual distinct elements? For the last of these, you could use var(['y_{}'.format(i) for i in set(m1)]).

John Palmieri gravatar imageJohn Palmieri ( 2022-03-29 19:16:38 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-03-29 11:53:00 +0100

tmonteil gravatar image

The n option for SR.var is supposed to be an integer, not an iterator. Do you mean the following ?

sage: y = var('y_', n=len(m1))
sage: y
(y_0, y_1, y_2)
edit flag offensive delete link more

Comments

Yes I am stupid

Cyrille gravatar imageCyrille ( 2022-03-29 22:45:36 +0100 )edit

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

Stats

Asked: 2022-03-29 11:24:34 +0100

Seen: 166 times

Last updated: Mar 29 '22