473,385 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.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
5 1193
"ðÏ" <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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
0
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n numbers. def combo2(n): return...
7
by: andrea | last post by:
I was thinking to code the huffman algorithm and trying to compress something with it, but I've got a problem. How can I represent for example a char with only 3 bits?? I had a look to the...
55
by: Ennixo | last post by:
hi, do you know where i can find some ebooks or websites talking about C# optimisation ? for exemple, i just learned that ++i is faster than i++. i would like to know more about the things...
0
by: Tim Golden | last post by:
甜瓜 wrote: Well I can't say I'd format it that way myself, but it is valid. More conventionally laid out the expression looks like this: x & 528 or x in l meaning:
21
by: hrishy | last post by:
Hi Will LINQ be ported to Python ? regards Hrishy
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.