George Sakkis a écrit :
> Bruno Desthuilliers wrote:
>
>
>>George Sakkis a écrit :
>>
>>>The thing is there are four (at least?) ways to get a dict instance:
>>>
(snip)
>>This actually makes 2 (two) ways of creating a dict:
>>- the default call to type (ie : dict(...)
>>- the syntactic sugar dic
Duncan Booth wrote:
> George Sakkis wrote:
>
> > Duncan Booth wrote:
> >
> >> George Sakkis wrote:
> >>
> >> > 2) restricting in a more serious sense: the future addition of
> >> > optional keyword arguments that affect the dict's behaviour. Google
> >> > for "default dict" or "dictionary accumula
Duncan Booth <[EMAIL PROTECTED]> writes:
> > d = dict(default=0)
> > d['x'] += 3
> >
> > more elegant than
> >
> > d = {}
> > d.withdefault(0)
> > d['x'] += 3
> >
> Well you could have:
>
> d = dict.withdefault(0)
>
> but then you may have to start with an empty dictionary. What happens if
>
George Sakkis wrote:
> Duncan Booth wrote:
>
>> George Sakkis wrote:
>>
>> > 2) restricting in a more serious sense: the future addition of
>> > optional keyword arguments that affect the dict's behaviour. Google
>> > for "default dict" or "dictionary accumulator".
>>
>> There is nothing to stop
Bruno Desthuilliers wrote:
> George Sakkis a écrit :
> > The thing is there are four (at least?) ways to get a dict instance:
> >
> > In [1]: d1={'name':'mike', 'age':23}
> >
> > In [2]: d2=dict(d1)
> >
> > In [3]: d3=dict(**d1)
> >
> > In [4]: d4=dict(d1.items())
> >
> > In [5]: d1==d2==d3==d4
>
George Sakkis a écrit :
> bruno de chez modulix en face wrote:
>
>
>>>and there's no compelling reason for dict(**kwds).
>>
>>Yes there is : this *is* the ordinary Python syntax - calling a type to
>>get an instance of it. The dict-litteral syntax is mostly syntactic
>>sugar.
>
>
> The thing i
Duncan Booth wrote:
> George Sakkis wrote:
>
> > 2) restricting in a more serious sense: the future addition of optional
> > keyword arguments that affect the dict's behaviour. Google for "default
> > dict" or "dictionary accumulator".
>
> There is nothing to stop dictionaries being created using
George Sakkis wrote:
> Perhaps you fail to understand that the given feature is
> 1) redundant (see above).
Yes, but a certain degree of redundancy in the language is inevitable, and
when it exists (as in this case) to make people's life easier it may be a
good thing. Obviously the tradeoff bet
bruno de chez modulix en face wrote:
> > and there's no compelling reason for dict(**kwds).
>
> Yes there is : this *is* the ordinary Python syntax - calling a type to
> get an instance of it. The dict-litteral syntax is mostly syntactic
> sugar.
The thing is there are four (at least?) ways to g
> Hm, as far as I know shadowing the builtins is discouraged.
*accidentally* shadowing builtins is a common Python gotcha - that's
why it's comon here to raise *warnings* about this.
Explicitly and knowingly rebinding a builtin (or any other name FWIW)
*with a compatible object* is something else
bruno at modulix wrote:
> When all your keys are valid Python identifiers, and you may want to use
> another dict-like instead of the builtin dict. It's easy to replace the
> dict() factory in a function, class, or whole module :
>
> class MyDict(...):
> # dict-like class
>
> dict = MyDict
>
> t
George Sakkis wrote:
> Bruno Desthuilliers wrote:
>
>
>>George Sakkis a écrit :
>>
>>>Although I consider dict(**kwds) as one of the few unfortunate design
>>>choices in python since it prevents the future addition of useful
>>>keyword arguments (e.g a default value or an orderby function), I've
George Sakkis <[EMAIL PROTECTED]> wrote:
> Bruno Desthuilliers wrote:
>
> > George Sakkis a écrit :
> > > Although I consider dict(**kwds) as one of the few unfortunate design
> > > choices in python since it prevents the future addition of useful
> > > keyword arguments (e.g a default value or a
Bruno Desthuilliers wrote:
> George Sakkis a écrit :
> > Although I consider dict(**kwds) as one of the few unfortunate design
> > choices in python since it prevents the future addition of useful
> > keyword arguments (e.g a default value or an orderby function), I've
> > been finding myself late
George Sakkis a écrit :
> Although I consider dict(**kwds) as one of the few unfortunate design
> choices in python since it prevents the future addition of useful
> keyword arguments (e.g a default value or an orderby function), I've
> been finding myself lately using it sometimes instead of dict
15 matches
Mail list logo