[Python-ideas] Mapping unpacking assignment

2022-02-03 Thread Stephen J. Turnbull
Yurii Karabas writes:

 > I am proposing to add smth like JS destructing assignment to python.
 > Basically, it will allow unpacking any mapping (should have
 > __getitem__ and keys() methods) into variables.

Ideas like this have been suggested before, with a number of
variations on syntax (specifically with unpacking into a tuple,
usually notated without parentheses).

I don't recall the more principled objections, but FWIW I'm about -0.5
because IAGNI, and it's one more thing to learn.



___
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/HVUSTZK5KZXJIBDR7XH677XD3MTAFVFX/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Mapping unpacking assignment

2022-02-03 Thread Yurii Karabas
I can, but it seems like the wrong usage of pattern matching and it requires 
much more code.
```
match m:
case {"a": a, "b": b, **rest}:
pass
case _:
raise ValueError
```

We can use pattern matching to unpack sequences, but we have special syntax for 
this:
```
s = range(100)

match s:
case (a, b, *rest):
pass
case _:
raise ValueError

(a, b, *rest) = s  # solve same problem with one line
```
___
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/GCMKZFHIB5S6DT24HZ42WLEUBMGTGJKU/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Mapping unpacking assignment

2022-02-03 Thread Piper Thunstrom
On Thu, Feb 3, 2022 at 11:51 AM Yurii Karabas <1998uri...@gmail.com> wrote:
>
> I am proposing to add smth like JS destructing assignment to python.
> Basically, it will allow unpacking any mapping (should have __getitem__ and 
> keys() methods) into variables.
>
> Proposed syntax:
> ```
> m = {"a": 1, "b": 2, "c": 3, "d": 4}
>
> {a, b} = m # a: 1, b: 2
> {a, b, **rest} = m # a: 1, b: 2, rest: {c: 3, d: 4}
> ```

Can't you solve the same problem with structural pattern matching
against mappings?
https://www.python.org/dev/peps/pep-0622/#mapping-patterns

Piper Thunstrom
Senior Software Engineer/Open Source Maintainer
___
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/GBNGVK72CJE4AT52M6N5BWJIAX6UVNXX/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Adding sortedconatiners to Python or merge the ideas?

2022-02-03 Thread Abdur-Rahmaan Janhangeer
Oh hoping over to read. I glanced but have not yet read it in details ...

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius
___
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/5RVC3LA3WYVCXCVWJANOZRVFJXXITMHB/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Adding sortedconatiners to Python or merge the ideas?

2022-02-03 Thread Barry


> On 3 Feb 2022, at 18:53, Abdur-Rahmaan Janhangeer  
> wrote:
> 
> Fine discussion but i wonder how it ended up over there.
> Hoping over. Thanks for pointers!

Please don’t top post.

The thinking on python dev seems to be that if a package is not needed by core 
python
then PyPI is the best place for it. I know you read python dev isn’t that what 
you
have sensed as well?

Barry


___
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/AKJQLJZ6KX5SBXSB52V6LMV4AWNOO45Q/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Mapping unpacking assignment

2022-02-03 Thread Yurii Karabas
I am proposing to add smth like JS destructing assignment to python.
Basically, it will allow unpacking any mapping (should have __getitem__ and 
keys() methods) into variables.

Proposed syntax:
```
m = {"a": 1, "b": 2, "c": 3, "d": 4}

{a, b} = m # a: 1, b: 2
{a, b, **rest} = m # a: 1, b: 2, rest: {c: 3, d: 4}
```

It will be rawly equal to:
```
m = {"a": 1, "b": 2, "c": 3, "d": 4}

# {a, b} = m
a = m["a"]
b = m["b"]

# {a, b, **rest}
rest = {**m}
a = rest.pop("a")
b = rest.pop("b")
```

This is fully backward compatible feature because currently syntax like above 
is not supported:
```
{a, b} = m # a: 1, b: 2
^^
SyntaxError: cannot assign to set display here. Maybe you meant '==' instead of 
'='?
```
___
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/XWYDTMI7HVVDBENMFAAFQNAIHTDPUCUZ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Adding sortedconatiners to Python or merge the ideas?

2022-02-03 Thread Abdur-Rahmaan Janhangeer
Fine discussion but i wonder how it ended up over there.
Hoping over. Thanks for pointers!

On Thu, 3 Feb 2022, 21:23 Damian Shaw,  wrote:

> This was very recently discussed at length:
> https://mail.python.org/archives/list/python-...@python.org/thread/YB2JD477TKPB2HTXDW6ZXUBD6NFFFHHJ/#YB2JD477TKPB2HTXDW6ZXUBD6NFFFHHJ
>
> Damian (he/him)
>
> On Thu, Feb 3, 2022 at 11:51 AM Abdur-Rahmaan Janhangeer <
> arj.pyt...@gmail.com> wrote:
>
>> Greetings,
>>
>> This library* seems to be used by many people for some treemap operations.
>> Would it be a good idea to include it in upcoming versions? Leetcode
>> has it by default for the lack of a similar something in Python. I did
>> not check,
>> but it seems other languages cater to structures better.
>>
>> * http://www.grantjenks.com/docs/sortedcontainers/
>>
>> Thanks.
>>
>> Kind Regards,
>>
>> Abdur-Rahmaan Janhangeer
>> about  | blog
>> 
>> github 
>> Mauritius
>> ___
>> 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/ASMXPU6O2NDZG32MQFMYQKCKTFKET4FE/
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
> ___
> 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/VM2QRXQ54FZPSA5UZ7PKNYRDUKBEDLDM/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
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/366R73DELGJGVQP3VAPITXYI77BTTANH/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Adding sortedconatiners to Python or merge the ideas?

2022-02-03 Thread Damian Shaw
This was very recently discussed at length:
https://mail.python.org/archives/list/python-...@python.org/thread/YB2JD477TKPB2HTXDW6ZXUBD6NFFFHHJ/#YB2JD477TKPB2HTXDW6ZXUBD6NFFFHHJ

Damian (he/him)

On Thu, Feb 3, 2022 at 11:51 AM Abdur-Rahmaan Janhangeer <
arj.pyt...@gmail.com> wrote:

> Greetings,
>
> This library* seems to be used by many people for some treemap operations.
> Would it be a good idea to include it in upcoming versions? Leetcode
> has it by default for the lack of a similar something in Python. I did not
> check,
> but it seems other languages cater to structures better.
>
> * http://www.grantjenks.com/docs/sortedcontainers/
>
> Thanks.
>
> Kind Regards,
>
> Abdur-Rahmaan Janhangeer
> about  | blog
> 
> github 
> Mauritius
> ___
> 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/ASMXPU6O2NDZG32MQFMYQKCKTFKET4FE/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
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/VM2QRXQ54FZPSA5UZ7PKNYRDUKBEDLDM/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Adding sortedconatiners to Python or merge the ideas?

2022-02-03 Thread Abdur-Rahmaan Janhangeer
Greetings,

This library* seems to be used by many people for some treemap operations.
Would it be a good idea to include it in upcoming versions? Leetcode
has it by default for the lack of a similar something in Python. I did not
check,
but it seems other languages cater to structures better.

* http://www.grantjenks.com/docs/sortedcontainers/

Thanks.

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius
___
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/ASMXPU6O2NDZG32MQFMYQKCKTFKET4FE/
Code of Conduct: http://python.org/psf/codeofconduct/