[Python-ideas] Re: Add .except() and .only(), and .values_at(). instance methods to dict

2022-06-05 Thread Steven D'Aprano
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

[Python-ideas] Re: Add .except() and .only(), and .values_at(). instance methods to dict

2022-06-05 Thread David Mertz, Ph.D.
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']}

[Python-ideas] Add .except() and .only(), and .values_at(). instance methods to dict

2022-06-05 Thread Steve Jorgensen
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}

[Python-ideas] Re: Addition to fnmatch.py

2022-06-05 Thread Eric V. Smith via Python-ideas
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

[Python-ideas] Re: Addition to fnmatch.py

2022-06-05 Thread Benedict Verhegghe
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,

[Python-ideas] Re: Addition to fnmatch.py

2022-06-05 Thread David Mertz, Ph.D.
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

[Python-ideas] Re: Addition to fnmatch.py

2022-06-05 Thread MRAB
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

[Python-ideas] Re: Addition to fnmatch.py

2022-06-05 Thread Jean Abou Samra
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

[Python-ideas] Re: Addition to fnmatch.py

2022-06-05 Thread David Mertz, Ph.D.
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

[Python-ideas] Addition to fnmatch.py

2022-06-05 Thread John Carter
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