very rare python expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?GB2312?B?zPC5zw==?=

    very rare python expression

    Howdy everyone,

    I saw a strange python code in pygame project. What does "while
    not(x&528or x in l):" mean? Below code works in python2.5, so "x&528"
    is not HTML strings.

    # snake.py code:
    import pygame as p,random
    p.init()
    q=p.display
    T=16
    b=q.set_mode([256]*2).fill
    l=[]
    d=a=x=1
    c=p.event.get
    while not(x&528or x in l):
    l=l[a!=x:]+[x]
    while a&528or a in l:a=random.rand range(512)
    b(0)
    [b(99,(o%T*T,o/32*T,T,T))for o in l+[a]]
    q.flip()
    p.time.wait(199 )
    for e in c(2):
    v=e.key-272
    n=((v&2)-1)*[1,32][v<3]
    if-n-d and 0<v<5:d=n
    c()
    x=l[-1]+d


    Best regards,

    --
    ShenLei
  • Paul Rubin

    #2
    Re: very rare python expression

    "ðÏ" <littlesweetmel on@gmail.comwri tes:
    I saw a strange python code in pygame project. What does "while
    not(x&528or x in l):" mean? Below code works in python2.5, so "x&528"
    is not HTML strings.
    It parses as "x & 528 or x in l". Looks like it came from

    A snake game written to be as small as possible.


    and is an attempt to squash the program to as few bytes as possible.

    Comment

    • Wojtek Walczak

      #3
      Re: very rare python expression

      Dnia Tue, 12 Aug 2008 16:39:27 +0800, =?GB2312?B?zPC5 zw==?= napisa³(a):
      Howdy everyone,
      >
      I saw a strange python code in pygame project. What does "while
      not(x&528or x in l):" mean? Below code works in python2.5, so "x&528"
      is not HTML strings.
      It looks like a check if 528 flag is set. In this way you can set
      more than one flag in signle variable:
      >>flag1 = 1
      >>flag2 = 2
      >>flag3 = 4
      >>flag4 = 8
      >>flag5 = 10
      >>flags_set = flag2 | flag4
      >>flags_set & flag1
      0
      >>flags_set & flag2
      2
      >>flags_set & flag3
      0
      >>flags_set & flag4
      8
      >>flags_set & flag5
      0


      --
      Regards,
      Wojtek Walczak,

      Comment

      • =?GB2312?B?zPC5zw==?=

        #4
        Re: very rare python expression

        Oh, thank you very much. I did know that python can parse number '528'
        and keyword 'or' without separator.

        2008/8/12 Paul Rubin <"http://phr.cx"@nospam. invalid>:
        "ðÏ" <littlesweetmel on@gmail.comwri tes:
        >I saw a strange python code in pygame project. What does "while
        >not(x&528or x in l):" mean? Below code works in python2.5, so "x&528"
        >is not HTML strings.
        >
        It parses as "x & 528 or x in l". Looks like it came from
        >
        A snake game written to be as small as possible.

        >
        and is an attempt to squash the program to as few bytes as possible.
        --

        >

        Comment

        • Edward A. Falk

          #5
          Re: very rare python expression

          In article <7xtzdqobsy.fsf @ruckus.brouhah a.com>,
          Paul Rubin <http://phr.cx@NOSPAM.i nvalidwrote:
          >"ðÏ" <littlesweetmel on@gmail.comwri tes:
          >I saw a strange python code in pygame project. What does "while
          >not(x&528or x in l):" mean? Below code works in python2.5, so "x&528"
          >is not HTML strings.
          >
          >It parses as "x & 528 or x in l". Looks like it came from
          >
          A snake game written to be as small as possible.

          >
          >and is an attempt to squash the program to as few bytes as possible.
          Sheesh. The 80's called; they want their floppy drives back.

          Even with the whitespace restored, it's awful style.

          --
          -Ed Falk, falk@despams.r. us.com

          Comment

          • Fredrik Lundh

            #6
            Re: very rare python expression

            Edward A. Falk wrote:
            >It parses as "x & 528 or x in l". Looks like it came from
            >>
            > http://www.pygame.org/project/833/
            >>
            >and is an attempt to squash the program to as few bytes as possible.
            >
            Sheesh. The 80's called; they want their floppy drives back.
            >
            Even with the whitespace restored, it's awful style.
            complaints about style issues in code intentionally written to be as
            short as possible? is this Digg, or what?

            </F>

            Comment

            Working...