• comprehension parsing

    From cactus@21:1/5 to All on Sat Nov 5 09:06:41 2022
    The two comprehensions:

    all((srt(n, m) in c_np) == (srt(a, b) in c_ap) for (m, b) in na)

    all( srt(n, m) in c_np == srt(a, b) in c_ap for (m, b) in na)

    parse differently but I am unclear what the second one produces since I thought it would be the same as the first.

    Any ideas how the second one parses?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to cactus on Sat Nov 5 16:52:31 2022
    cactus <[email protected]> writes (shortened):
    (srt(n, m) in c_np) == (srt(a, b) in c_ap)

    parses as something like

    Compare
    ( left = Compare( left=srt( n, m ), operator=in, comparator=c_np ),
    operator = eq,
    comparator =
    [ Compare( left=srt( a, b ), operator=in, comparator=c_ap )])

    , while

    srt(n, m) in c_np == srt(a, b) in c_ap

    parses as something like

    Compare
    ( left = srt( n, m ),
    operators =[ in, eq, in ],
    comparators =[ c_np, srt(a, b), c_ap ]).

    This should be the left-associative sequence, if I guess the
    meaning of "Compare" of the module "ast" correctly, i.e.,
    (( srt( n, m )in c_np )== srt( a, b ))in c_ap.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From cactus@21:1/5 to All on Sat Nov 5 11:52:09 2022
    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))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MRAB@21:1/5 to cactus on Sat Nov 5 22:11:38 2022
    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'.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From BlindAnagram@21:1/5 to MRAB on Sat Nov 5 23:54:42 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From philippe descharmes@21:1/5 to All on Sun Nov 6 02:55:00 2022
    Hello, I‌ts probably a priority of avalauation in the chain of operators ans association of themselves. I'm not sure. Philippe.
     

    De : "BlindAnagram"
    A : [email protected]
    Envoyé: dimanche 6 Novembre 2022 00:57
    Objet : Re: comprehension parsing
     
    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 -- https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)