On Sun, Jun 05, 2022 at 09:11:41PM -, Steve Jorgensen wrote:
> m = {'a': 123, 'b': 456, 'c': 789}
> m.except(('a', 'c')) # {'b': 456}
> m.only(('b', 'c')) # {'b': 456, 'c': 789}
> m.values_at(('a', 'b')) # [123, 456]
Maybe I'm a bit slow because I haven't had my morning coffee yet, but I
These are all far too easy to do with comprehensions to merit new methods
or stdlib functions.
m = {'a': 123, 'b': 456, 'c': 789}
>
m.except(('a', 'c')) # {'b': 456}
> m.only(('b', 'c')) # {'b': 456, 'c': 789}
> m.values_at(('a', 'b')) # [123, 456]
>
{k:m[v] for k in m if k not in ['a','c']}
I think these are an extremely common needs that are worth having standard
methods for. If adding instance methods seems like a bad idea, then maybe add
functions to the standard library that perform the same operations.
m = {'a': 123, 'b': 456, 'c': 789}
m.except(('a', 'c')) # {'b': 456}
On 6/5/2022 1:22 PM, Benedict Verhegghe wrote:
Op 5/06/2022 om 18:47 schreef David Mertz, Ph.D.:
Sure, that's nice enough code and has the same big-O complexity. I
suspect set difference is a little faster (by a constant multiple)
because it hits C code more, but I haven't benchmarked.
The
Op 5/06/2022 om 18:47 schreef David Mertz, Ph.D.:
Sure, that's nice enough code and has the same big-O complexity. I
suspect set difference is a little faster (by a constant multiple)
because it hits C code more, but I haven't benchmarked.
The OP said the elements were from fnmatch though,
On Sun, Jun 5, 2022, 12:08 PM MRAB wrote:
> On 2022-06-05 16:12, David Mertz, Ph.D. wrote:
> > This is exactly the problem solved by set difference. E.g. `{a, b, c}
> - {a, c}`.
> >
> > This operation is linear on the size of the removed set.
> >
> You don't have to use a set difference, which
On 2022-06-05 16:12, David Mertz, Ph.D. wrote:
This is exactly the problem solved by set difference. E.g. `{a, b, c} -
{a, c}`.
This operation is linear on the size of the removed set.
You don't have to use a set difference, which might matter if the order
was important, but just make a set
Le 05/06/2022 à 16:52, John Carter a écrit :
I’d like to propose a simple addition to the 'fnmatch' module. Specificity a
function that returns a list of names that match a pattern AND a list of those
that don't.
In a recent project I found that I wished to split a list of files and move
This is exactly the problem solved by set difference. E.g. `{a, b, c} - {a,
c}`.
This operation is linear on the size of the removed set.
On Sun, Jun 5, 2022, 11:01 AM John Carter wrote:
> I’d like to propose a simple addition to the 'fnmatch' module. Specificity
> a function that returns a
I’d like to propose a simple addition to the 'fnmatch' module. Specificity a
function that returns a list of names that match a pattern AND a list of those
that don't.
In a recent project I found that I wished to split a list of files and move
those that matched a pattern to one folder and
10 matches
Mail list logo