Oh I forgot what if you want to return a set from your lambda? Maybe a lambda 
set should at least have one assignment statement to qualify it as one. 
Expressions only inside a set syntax will be just a normal set that doesn’t 
care about order as you pointed out. But a lambda set will care about the order 
just like when you do a normal multi-lines def function. 
def f(x):
    print(x)
    z = x + 3 
    return z 
Is equivalent to
(x) => {print(x), z = x + 3, z}
since “z = x + 3” is an assignment statement, this would be qualified as a 
lambda set. Normal set will not be possible as that will throw syntax error. So 
the side effect is a printed x and the return is just z.

If you write something like the following:
(x) => {print(x), x +3} 
Make x = 1 and the return value will be just a normal set of {None, 4} or {4, 
None} with a printed 1 as a side effect.

Abdulla

Sent from my iPhone

> On 3 Oct 2021, at 8:29 PM, Eric Fahlgren <ericfahlg...@gmail.com> wrote:
> 
> 
> I'm somewhat confused by the term "last item of the set", as sets are not 
> ordered and have no "last" element:
> 
> >>> {1,3,3,2}
> {1, 2, 3}
> 
>> On Sat, Oct 2, 2021 at 8:23 PM Abdulla Al Kathiri 
>> <alkathiri.abdu...@gmail.com> wrote:
>> Then use it with the normal expression lambda: 
>> people.sort(key=p => (p.salary, p.name, p.id)). 
>> You don’t need lambda set for that. If you want to use it, it will be like 
>> the following: 
>> people.sort(key=p => {(p.salary, p.name, p.id)}). The tuple expression is 
>> the last item of the set, so the tuple is the return value. 
>> Abdulla
>> 
>> Sent from my iPhone
>> 
>> > On 3 Oct 2021, at 2:25 AM, Chris Angelico <ros...@gmail.com> wrote:
>> > 
>> > people.sort(key=lambda p: (p.salary, p.name, p.id))
>> _______________________________________________
>> 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/YJKNUXZD6JJONZT6YY23OAFBB5QVWCA2/
>> 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/QQLJJTSF27TSHTUMVW2KZ6KYB7T6MANN/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to