On Friday 12 October 2007 13:36, Mike Hansen wrote:
> If you're doing a dictionary anyway, doesn't it make more sense to use
> **kwargs?  For example,
>
> sage: P.<x,y>=ZZ[]
> sage: f=x*y^2+x*y+y+x+1
> sage: f.coefficient(y=2)
> x
> sage: f.coefficient(y=1)
> x + 1
> sage: f.coefficient(x=1, y=2)
> 1
>
> It takes a little bit to get used to the semantics of it, but the
> syntax is much more natural / Pythonic.

Hmm, possibly.  kwargs feels scary to me with variables since the 'x' in the 
kwargs parameter list is a totally different 'x' than the one in P.gen(0).  
They just happened to be named the same in some different scope.  I think 
that allowing both methods might be ok.

Another more concrete reason is that I want to do something like this:

P=PolynomialRing(ZZ,'x',n)
d={}
d[P.gen(1)] = 1
d[P.gen(2)] = 2
poly.coefficient(d)

That is, I want to fill out my dictionary very dynamically.  I suppose there 
is probably a way to do this with kwargs, but it feels like a reach into some 
dark corner syntactically.

--
Joel

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to