Ask Your Question
0

cancel one dict entry

asked 2016-12-01 11:50:24 +0100

louisgag gravatar image

Using sage notebook, is there a way to cancel an entry from an already defined dictionary without rewriting the whole dict ?

For example, let's say my sage worksheet goes as such:
soln = {}; # defining dictionary
soln[b] = 0.5
soln[c] = 0.2
soln[N] = 6;
etc. for many more soln entries

Then I do something which requires all values in soln, and after, I want to plot a function which uses all of soln values but one, say N. How can I cancel it ?

What I currently do is rerun my whole worksheet cell by cell after having commented the soln[N] = 6; line, but it takes more time than I'd like.

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2016-12-01 12:05:14 +0100

Sébastien gravatar image

You may delete entry soln[N] of your dict using del soln[N] :

sage: b,c,N = var('b c N')
sage: soln = {}; # defining dictionary
....: soln[b] = 0.5
....: soln[c] = 0.2
....: soln[N] = 6;
....: 
sage: del soln[N]
sage: soln
{b: 0.500000000000000, c: 0.200000000000000}
edit flag offensive delete link more

Comments

Great! Didn't know the trick was so simple. Thanks. -Louis

louisgag gravatar imagelouisgag ( 2016-12-01 12:11:15 +0100 )edit

@louisgag, you can click the checkmark icon next to the answer to mark it as the accepted answer.

This way, your question will appear as "answered with an accepted answer" in the list of questions.

slelievre gravatar imageslelievre ( 2016-12-11 13:11:45 +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: 2016-12-01 11:50:24 +0100

Seen: 500 times

Last updated: Dec 01 '16