Ask Your Question
0

cancel one dict entry

asked 8 years ago

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!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 8 years ago

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}
Preview: (hide)
link

Comments

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

louisgag gravatar imagelouisgag ( 8 years ago )

@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 ( 8 years ago )

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: 8 years ago

Seen: 539 times

Last updated: Dec 01 '16