comprehension parsing
BlindAnagram
BlindAnagram at nowhere.org
Sat Nov 5 19:54:42 EDT 2022
On 05/11/2022 22:11, MRAB wrote:
> On 2022-11-05 18:52, cactus wrote:
>> On Saturday, 5 November 2022 at 16:06:52 UTC, cactus wrote:
>>
>> I should have quoted the full comprehensions:
>>
>> all((srt(m, n) in c_np) == (srt(a, b) in c_ap) for (m, a), (n, b)
>> in combinations(na8, 2))
>> all( srt(m, n) in c_np == srt(a, b) in c_ap) for (m, a), (n, b)
>> in combinations(na8, 2))
>
> The comparison operators can be chained, so:
>
> a == b == c
>
> is equivalent to:
>
> (a == b) and (b == c)
>
> except that the common term ('b' in this case) is evaluated only once.
>
> 'in' is one of those comparison operators, so:
>
> srt(m, n) in c_np == srt(a, b) in c_ap
>
> is equivalent to:
>
> (srt(m, n) in c_np) and (c_np == srt(a, b)) and (srt(a, b) in c_ap)
>
> except that the common terms ('c_np' and 'srt(a, b)') are evaluated only
> once.
>
> Chaining makes most sense with multiple '==' or a series of '<' and/or
> '<=' or a series of '>' and/or '>=', as in '1 <= n <= 10'.
Thanks for a most helpful explanation
More information about the Python-list
mailing list