By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,925 Members | 1,824 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,925 IT Pros & Developers. It's quick & easy.

very rare python expression

P: n/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.

# 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.randrange(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
Aug 12 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"­¤" <li**************@gmail.comwrites:
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

http://www.pygame.org/project/833/

and is an attempt to squash the program to as few bytes as possible.
Aug 12 '08 #2

P: n/a
Dnia Tue, 12 Aug 2008 16:39:27 +0800, =?GB2312?B?zPC5zw==?= 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,
http://www.stud.umk.pl/~wojtekwa/
Aug 12 '08 #3

P: n/a
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>:
"­¤" <li**************@gmail.comwrites:
>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

http://www.pygame.org/project/833/

and is an attempt to squash the program to as few bytes as possible.
--
http://mail.python.org/mailman/listinfo/python-list
Aug 12 '08 #4

P: n/a
In article <7x************@ruckus.brouhaha.com>,
Paul Rubin <http://ph****@NOSPAM.invalidwrote:
>"­¤" <li**************@gmail.comwrites:
>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

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.

--
-Ed Falk, fa**@despams.r.us.com
http://thespamdiaries.blogspot.com/
Aug 12 '08 #5

P: n/a
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>

Aug 13 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.