Giovanni Bajo wrote,
> dict.setdefault, as I already explained to you.
I wonder about numerics too. Say we have a = None somewhere.
I want to increment it, so I'd say a += 8. Now if this is a parsing
app, the increment may happen everywhere -- so I'd write a function to
do it if I worry about
braver wrote:
> Also, what's the shortest python idiom for get_or_set in expression?
dict.setdefault, as I already explained to you.
Again, I'd like to point out that what you're doing is *not* the correct
Pythonic way of doing things. In Python, there is simply no implicit
sub-dicts creation, n
On Tue, 17 Jan 2006 18:00:00 -0700, Steven Bethard wrote:
> Steve Holden wrote:
>> Steven Bethard wrote:
>>> Agreed. I really hope that Python 3.0 applies Raymond Hettinger's
>>> suggestion "Improved default value logic for Dictionaries" from
>>> http://wiki.python.org/moin/Python3%2e0Sugge
Steven Bethard wrote:
> Steve Holden wrote:
>
>>Steven Bethard wrote:
>>
>>>Agreed. I really hope that Python 3.0 applies Raymond Hettinger's
>>>suggestion "Improved default value logic for Dictionaries" from
>>> http://wiki.python.org/moin/Python3%2e0Suggestions
>>>
>>>This would allow you
braver wrote:
> Thanks, James! This is really helpful.
>
> : It would take a lot of coding to make that << work right. Better is
> the pythonic
> :
> : m[key] = [value]
> :
> : Its really only one more keystroke than
> :
> : m[key] << value
>
> But it's only for the first element, right? I'd ha
On Tue, 17 Jan 2006 16:47:15 -0800, James Stroud <[EMAIL PROTECTED]> wrote:
>braver wrote:
>> Well, I know some python, but since there are powerful and magical
>> features in it, I just wonder whether there're some which address this
>> issue better than others.
>>
>
>In python, += is short, of co
Thanks, James! This is really helpful.
: It would take a lot of coding to make that << work right. Better is
the pythonic
:
: m[key] = [value]
:
: Its really only one more keystroke than
:
: m[key] << value
But it's only for the first element, right? I'd have to say
meh[key1]...[keyN].append(el
Steve Holden wrote:
> Steven Bethard wrote:
>> Agreed. I really hope that Python 3.0 applies Raymond Hettinger's
>> suggestion "Improved default value logic for Dictionaries" from
>> http://wiki.python.org/moin/Python3%2e0Suggestions
>>
>> This would allow you to make the setdefault() call o
braver wrote:
> Well, I know some python, but since there are powerful and magical
> features in it, I just wonder whether there're some which address this
> issue better than others.
>
In python, += is short, of course, for
a = a + 1
But if we haven't already assigned a, how does the interpret
Well, I know some python, but since there are powerful and magical
features in it, I just wonder whether there're some which address this
issue better than others.
--
http://mail.python.org/mailman/listinfo/python-list
"braver" <[EMAIL PROTECTED]> writes:
> Can assigning to hash without intermediate levels, possibly adding to a
> numeric leaf or adding an element to a leaf array, be python code?
>
> h['a']['b']['c'] += 42
>
> If it can, I'd like to have a class which supports it.
Yes, it's simple enough to wri
Can assigning to hash without intermediate levels, possibly adding to a
numeric leaf or adding an element to a leaf array, be python code?
h['a']['b']['c'] += 42
If it can, I'd like to have a class which supports it.
Is keeping a list at the leaf of a hash python code?
h['a']['b']['c'].push(7)
"braver" wrote:
> The point of this exercise is to compare how either ruby or python can
> implement perl's default behavior when dealing with hashes. Since
> these are bread and butter of scripting, having a MEH class handy can
> enable fast semantically equivalent translation. This can be
> be
The point of this exercise is to compare how either ruby or python can
implement perl's default behavior when dealing with hashes. Since
these are bread and butter of scripting, having a MEH class handy can
enable fast semantically equivalent translation. This can be
beneficial for demonstrating
"braver" wrote
> Exactly, << as in C++/ruby streams. But notice the extra checks needed
> to see whether we want a new leaf which is an array or a number, or we
> create an intermediate hash level. Would the checks look the same in
> python?
we?
trust me, the number of people who think it's a
"braver" <[EMAIL PROTECTED]> writes:
> Exactly, << as in C++/ruby streams. But notice the extra checks needed
> to see whether we want a new leaf which is an array or a number, or we
> create an intermediate hash level. Would the checks look the same in
> python?
You could check what is being sh
"braver" wrote
> Exactly, << as in C++/ruby streams. But notice the extra checks needed
> to see whether we want a new leaf which is an array or a number, or we
> create an intermediate hash level. Would the checks look the same in
> python?
we?
trust me, the number of people who think it's a
Exactly, << as in C++/ruby streams. But notice the extra checks needed
to see whether we want a new leaf which is an array or a number, or we
create an intermediate hash level. Would the checks look the same in
python?
--
http://mail.python.org/mailman/listinfo/python-list
"braver" <[EMAIL PROTECTED]> writes:
> Actually, the behavior is important to translate perl into ruby. Can
> it be implemented in python looking similarly?
It's kind of bizarre in Python to use << as a mutation operator, but I
guess you could do it. Sort of like 'cout << "hello world"' in C++.
Steven Bethard wrote:
> Paul Rubin wrote:
>
>>Hmm,
>>
>> x[a][b][c][d] = e# x is a "magic" dict
>>
>>becomes
>>
>> x.setdefault(a,{}).setdefault(b,{}).setdefault(c,{})[d] = e
>>
>>if I understand correctly. Ugh.
>
>
> Agreed. I really hope that Python 3.0 applies Raymond Hettinger's
>
Actually, the behavior is important to translate perl into ruby. Can
it be implemented in python looking similarly?
--
http://mail.python.org/mailman/listinfo/python-list
"braver" <[EMAIL PROTECTED]> writes:
> Nice. What about pushing to leaves which are arrays, or incrementing
> leaves which are numbers? If the array leaf didn't exist, or a number
> wasn't set yet, << must create an empty array and push the element from
> the RHS into it, and += must init the lea
Nice. What about pushing to leaves which are arrays, or incrementing
leaves which are numbers? If the array leaf didn't exist, or a number
wasn't set yet, << must create an empty array and push the element from
the RHS into it, and += must init the leaf to 0 and add the RHS to it.
Here's the corr
Paul Rubin wrote:
> Hmm,
>
>x[a][b][c][d] = e# x is a "magic" dict
>
> becomes
>
>x.setdefault(a,{}).setdefault(b,{}).setdefault(c,{})[d] = e
>
> if I understand correctly. Ugh.
Agreed. I really hope that Python 3.0 applies Raymond Hettinger's
suggestion "Improved default value
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
> > BTW: remember that setdefault() is written "setdefault()" but it's read
> > "getorset()".
>
> I can only second that. The misleading name has - well, mislead me :)
Hmm,
x[a][b][c][d] = e# x is a "magic" dict
becomes
x.setdefault(a,{}
>
> BTW: remember that setdefault() is written "setdefault()" but it's read
> "getorset()".
I can only second that. The misleading name has - well, mislead me :)
Regards,
Diez
--
http://mail.python.org/mailman/listinfo/python-list
James Stroud wrote:
>> I need a magical expanding hash with the following properties:
>>
>> * it creates all intermediate keys
>>
>> meh['foo']['bar] = 1
>>
>> -- works even if meh['foo'] didn't exist before
>>
>
"braver" <[EMAIL PROTECTED]> writes:
> I need a magical expanding hash with the following properties: ...
> I have such a class in ruby. Can python do that?
Python's built-in dict objects don't do that but you could write such
a class pretty straightforwardly.
--
braver wrote:
> I need a magical expanding hash with the following properties:
>
> * it creates all intermediate keys
>
> meh['foo']['bar] = 1
>
> -- works even if meh['foo'] didn't exist before
>
> * allows pushing new elements to leav
I need a magical expanding hash with the following properties:
* it creates all intermediate keys
meh['foo']['bar] = 1
-- works even if meh['foo'] didn't exist before
* allows pushing new elements to leaves which are arrays
meh['foo']['list]
30 matches
Mail list logo