On 31/03/21 7:37 pm, dn wrote:
Python offers mutable (can be changed) and immutable (can't) objects
(remember: 'everything is an object'):
https://docs.python.org/3/reference/datamodel.html?highlight=mutable%20data
While that's true, it's actually irrelevant to this situation.
$ a = "bob"
On 31/03/2021 19.24, Loris Bennett wrote:
> dn writes:
>
>> On 31/03/2021 01.22, Loris Bennett wrote:
>>> Jon Ribbens writes:
On 2021-03-30, Loris Bennett wrote:
> If I have dict of dicts, say
>
> dod = {
> "alice":
> {
> "lang": "python",
>>
dn writes:
> On 31/03/2021 01.22, Loris Bennett wrote:
>> Jon Ribbens writes:
>>> On 2021-03-30, Loris Bennett wrote:
If I have dict of dicts, say
dod = {
"alice":
{
"lang": "python",
"level": "expert"
},
On 31/03/2021 01.22, Loris Bennett wrote:
> Jon Ribbens writes:
>> On 2021-03-30, Loris Bennett wrote:
>>> If I have dict of dicts, say
>>>
>>> dod = {
>>> "alice":
>>> {
>>> "lang": "python",
>>> "level": "expert"
>>> },
>>> "bob":
>>> {
>>>
> > For completeness, from 3.5 onwards, you can also do the following:
> > [{'name': n, **d} for n, d in dod.items()]
> Reading through these, personally I like this one best. I'm curious what
> about it was enabled in 3.5? Was **kwarg expansion inside a dict literal not
> possible before then? Any
On Wed, Mar 31, 2021 at 1:56 AM Travis Griggs wrote:
>
>
> > On Mar 30, 2021, at 12:11, Stestagg wrote:
> >
> > For completeness, from 3.5 onwards, you can also do the following:
> >
> > [{'name': n, **d} for n, d in dod.items()]
> >
>
> Reading through these, personally I like this one best. I'm
> On Mar 30, 2021, at 12:11, Stestagg wrote:
>
> For completeness, from 3.5 onwards, you can also do the following:
>
> [{'name': n, **d} for n, d in dod.items()]
>
Reading through these, personally I like this one best. I'm curious what about
it was enabled in 3.5? Was **kwarg expansion in
Jon Ribbens writes:
> On 2021-03-30, Loris Bennett wrote:
>> If I have dict of dicts, say
>>
>> dod = {
>> "alice":
>> {
>> "lang": "python",
>> "level": "expert"
>> },
>> "bob":
>> {
>> "lang": "perl",
>> "level": "noob"
>>
On Tue, Mar 30, 2021 at 11:21 PM Jon Ribbens via Python-list
wrote:
>
> On 2021-03-30, Chris Angelico wrote:
> > On Tue, Mar 30, 2021 at 11:01 PM Jon Ribbens via Python-list
> > wrote:
> >>
> >> On 2021-03-30, Chris Angelico wrote:
> >> > I dunno about "canonical", but here's how I'd do it:
> >>
On 2021-03-30, Chris Angelico wrote:
> On Tue, Mar 30, 2021 at 11:01 PM Jon Ribbens via Python-list
> wrote:
>>
>> On 2021-03-30, Chris Angelico wrote:
>> > I dunno about "canonical", but here's how I'd do it:
>> >
>> > lod = [info | {"name": name} for name, info in dod.items()]
>> >
>> > You cou
For completeness, from 3.5 onwards, you can also do the following:
[{'name': n, **d} for n, d in dod.items()]
On Tue, Mar 30, 2021 at 1:06 PM Chris Angelico wrote:
> On Tue, Mar 30, 2021 at 11:01 PM Jon Ribbens via Python-list
> wrote:
> >
> > On 2021-03-30, Chris Angelico wrote:
> > > I dunn
On Tue, Mar 30, 2021 at 11:01 PM Jon Ribbens via Python-list
wrote:
>
> On 2021-03-30, Chris Angelico wrote:
> > I dunno about "canonical", but here's how I'd do it:
> >
> > lod = [info | {"name": name} for name, info in dod.items()]
> >
> > You could use {"name":name}|info instead if you prefer
On 2021-03-30, Chris Angelico wrote:
> I dunno about "canonical", but here's how I'd do it:
>
> lod = [info | {"name": name} for name, info in dod.items()]
>
> You could use {"name":name}|info instead if you prefer to have the
> name show up first in the dictionary.
It's probably worth noting thi
On 2021-03-30, Loris Bennett wrote:
> If I have dict of dicts, say
>
> dod = {
> "alice":
> {
> "lang": "python",
> "level": "expert"
> },
> "bob":
> {
> "lang": "perl",
> "level": "noob"
> }
> }
>
> is there a canonic
On Tue, Mar 30, 2021 at 10:41 PM Loris Bennett
wrote:
>
> Hi,
>
> If I have dict of dicts, say
>
> dod = {
> "alice":
> {
> "lang": "python",
> "level": "expert"
> },
> "bob":
> {
> "lang": "perl",
> "level": "noob"
> }
I'm not certain this is the clearest possible code pattern to use, but
depending on the structure of your larger code, it's possible to do this,
and the compactness may help with understandability (that's a judgement
call!):
[dict(d, name=n) for n, d in dod.items()]
On Tue, Mar 30, 2021 at 12:42
Hi,
If I have dict of dicts, say
dod = {
"alice":
{
"lang": "python",
"level": "expert"
},
"bob":
{
"lang": "perl",
"level": "noob"
}
}
is there a canonical, or more pythonic, way of converting the outer key
to a val
17 matches
Mail list logo