[Python-ideas] Re: default as a keyword argument for dict.get and dict.pop

2022-06-07 Thread Chris Angelico
On Wed, 8 Jun 2022 at 00:36,  wrote:
>
> Hello!
>
> Do you know if there has been discussions around why is the default argument 
> is positional only in the dict methods get and pop?
>
> I think
>
> ```
> d.get(key, default=3)
> ```
>
> way more readable than
>
> ```
> d.get(key, 3)
> ```
>
> specially since max and min builtin functions use default as a keyword 
> argument.

With min and max, it MUST be a keyword argument, because positional
arguments are the values to be compared. So I think the main reason is
"because nobody ever bothered to do it". If there's enough value in
it, that could probably be changed, although mere consistency alone
isn't a very strong argument.

ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/26RTH4UI7B26DMWP6LSIK4VIAV7NCIQT/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: default as a keyword argument for dict.get and dict.pop

2022-06-07 Thread Steven D'Aprano
On Tue, Jun 07, 2022 at 02:28:51PM -, martineznicolas41...@gmail.com wrote:

> Do you know if there has been discussions around why is the default 
> argument is positional only in the dict methods get and pop?

Its probably just left over from earlier versions of Python when builtin 
functions only used positional arguments.

Positional arguments are a little faster than keyword arguments, and 
especially for builtin functions, easier to program.

You could try making an enhancement request on the bug tracker and see 
if any one is willing to do the work.

-- 
Steve
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/XX5IGYNZHBGVBWTKDAYRV7IH7P44TLDB/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] default as a keyword argument for dict.get and dict.pop

2022-06-07 Thread martineznicolas41541
Hello!

Do you know if there has been discussions around why is the default argument is 
positional only in the dict methods get and pop?

I think

```
d.get(key, default=3)
```

way more readable than 

```
d.get(key, 3)
```

specially since max and min builtin functions use default as a keyword argument.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/IFM3QL67EWQCROPIX3DNCR44F4ULMFD3/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2022-06-07 Thread MRAB

On 2022-06-07 11:03, Chris Angelico wrote:

On Tue, 7 Jun 2022 at 19:09, Ben Rudiak-Gould  wrote:


This calls the predicate once per element:

def partition(pred, iterable):
t1, t2 = tee((pred(x), x) for x in iterable)
return (x for b, x in t1 if not b), (x for b, x in t2 if b)

It's kind of inefficient though.


Honestly, if it weren't that there's currently a recipe in itertools,
I think the list-based version would be the best recipe to offer. The
cost of doing the job lazily AND maintaining all the other
expectations is too high; if you really need it to be lazy, it's
probably worth seeing if one of the other demands can be relaxed (eg
if it's fine to call the predicate twice).

For the OP's task, doing the partitioning eagerly wouldn't be an issue.

The problem with a lazy solution is that if you're producing 2 streams 
of output, as it were, and if you're consuming from only one of them, 
what are you going to do about the other one? You still need to store 
the items for it in case you want to consume them later, and if the 
original iterable is infinite, you have a problem...

___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/T3JM5DZSN55OEWINS2HYJAZJLOKLJWPJ/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2022-06-07 Thread Chris Angelico
On Tue, 7 Jun 2022 at 19:09, Ben Rudiak-Gould  wrote:
>
> This calls the predicate once per element:
>
> def partition(pred, iterable):
> t1, t2 = tee((pred(x), x) for x in iterable)
> return (x for b, x in t1 if not b), (x for b, x in t2 if b)
>
> It's kind of inefficient though.

Honestly, if it weren't that there's currently a recipe in itertools,
I think the list-based version would be the best recipe to offer. The
cost of doing the job lazily AND maintaining all the other
expectations is too high; if you really need it to be lazy, it's
probably worth seeing if one of the other demands can be relaxed (eg
if it's fine to call the predicate twice).

For the OP's task, doing the partitioning eagerly wouldn't be an issue.

ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/JA7C3XAP4H53VJBI2QR56XDJA2GQJN3W/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2022-06-07 Thread Ben Rudiak-Gould
This calls the predicate once per element:

def partition(pred, iterable):
t1, t2 = tee((pred(x), x) for x in iterable)
return (x for b, x in t1 if not b), (x for b, x in t2 if b)

It's kind of inefficient though.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/DQBFYD7KYRG6OOMXIY7IH45S25U6SXTK/
Code of Conduct: http://python.org/psf/codeofconduct/