On Tue, Feb 9, 2016 at 12:21 AM, Grobu wrote:
> On 08/02/16 17:12, Ian Kelly wrote:
>
>> dict does already expose set-like views. How about:
>>
>> {k: d[k] for k in d.keys() & s} # d & s
>> {k: d[k] for k in d.keys() - s} # d - s
>>
> Interesting. But seemingly only applies to Python 3.
Substit
On 08/02/16 17:12, Ian Kelly wrote:
dict does already expose set-like views. How about:
{k: d[k] for k in d.keys() & s} # d & s
{k: d[k] for k in d.keys() - s} # d - s
Interesting. But seemingly only applies to Python 3.
--
https://mail.python.org/mailman/listinfo/python-list
Marco Kaulea writes:
> In one talk (I think it was [1]) it was described that sets are basically
> dicts without the values.
It seems an unhelpful thing to say about ‘set’, I disagree with that
characterisation.
> Therefor it should be easy to apply set operations on dicts
Yes, t
On Mon, Feb 8, 2016 at 5:47 AM, Grobu wrote:
> You can use dictionary comprehension :
>
> Say :
> dict1 = {'a': 123, 'b': 456}
> set1 = {'a'}
>
> intersection :
{ key:dict1[key] for key in dict1 if key in set1 }
> {'a': 123}
>
> difference :
{ key:dict1[key] for key in dict1 if not key i
Random832 writes:
> On Mon, Feb 8, 2016, at 08:32, Matt Wheeler wrote:
>> On 8 February 2016 at 12:17, Jussi Piitulainen wrote:
>> > Also, what would be the nicest current way to express a priority union
>> > of dicts?
>> >
>> > { k:(d if k in d else e)[k] for k in d.keys() | e.keys() }
>>
>> Sin
On Mon, Feb 8, 2016, at 08:32, Matt Wheeler wrote:
> On 8 February 2016 at 12:17, Jussi Piitulainen
> wrote:
> > Also, what would be the nicest current way to express a priority union
> > of dicts?
> >
> > { k:(d if k in d else e)[k] for k in d.keys() | e.keys() }
>
> Since Python 3.5: {**e, **d}
Matt Wheeler writes:
> On 8 February 2016 at 12:17, Jussi Piitulainen wrote:
>> Also, what would be the nicest current way to express a priority union
>> of dicts?
>>
>> { k:(d if k in d else e)[k] for k in d.keys() | e.keys() }
>
> Since Python 3.5: {**e, **d}
Thanks. I have considered this news
On 8 February 2016 at 12:17, Jussi Piitulainen
wrote:
> Also, what would be the nicest current way to express a priority union
> of dicts?
>
> { k:(d if k in d else e)[k] for k in d.keys() | e.keys() }
Since Python 3.5: {**e, **d}
--
Matt Wheeler
http://funkyh.at
--
https://mail.python.org/ma
You can use dictionary comprehension :
Say :
dict1 = {'a': 123, 'b': 456}
set1 = {'a'}
intersection :
>>> { key:dict1[key] for key in dict1 if key in set1 }
{'a': 123}
difference :
>>> { key:dict1[key] for key in dict1 if not key in set1 }
{'b': 456}
--
https://mail.python.org/mailman/listinfo
On Mon, Feb 8, 2016 at 1:17 PM, Jussi Piitulainen <
jussi.piitulai...@helsinki.fi> wrote:
> I think nobody was quite willing to lay down the law on which dictionary
> would take precedence when they have keys in common but different values
> on those keys. Both ways make sense, and sometimes you w
Marco Kaulea writes:
> In one talk (I think it was [1]) it was described that sets are
> basically dicts without the values. Therefor it should be easy to
> apply set operations on dicts, for example:
>
> {'a': 123, 'b': 456} & {'a'} => {&
Hi,
In one talk (I think it was [1]) it was described that sets are basically
dicts without the values.
Therefor it should be easy to apply set operations on dicts, for example:
{'a': 123, 'b': 456} & {'a'} => {'a': 123}
{'a': 12
12 matches
Mail list logo