Created
August 21, 2008 15:23
-
-
Save qingfeng/6578 to your computer and use it in GitHub Desktop.
python tips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> engine_res | |
[1, 2, 3, 4, 6, 5, 7] | |
>>> db_res | |
[(4, 'no1'), (1, 'no1'), (7, 'no1'), (2, 'no1'), (5, 'no1'), (3, 'no1'), (6, 'no1')] | |
>>> sorted(db_res,key=lambda k:engine_res.index(k[0])) | |
[(1, 'no1'), (2, 'no1'), (3, 'no1'), (4, 'no1'), (6, 'no1'), (5, 'no1'), (7, 'no1')] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def func(a,b,c): | |
... print a,b,c | |
... | |
>>> func(*[1,2,3]) | |
1 2 3 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print '10X98765432'[reduce(lambda x,y +y, map(lambda x:int(x[0])*x[1], zip('51000018880101001'[0:17], [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]) )) % 11] | |
''' | |
想生成一个合法的18位良民证用于注册防沉迷?不妨试试上面的one liner python script。其中51000018880101001前5位是地区,接下来是生日,最后三位随便弄,奇数男的偶数女的。最后一位由上面的python代码获得。有的漏洞还可以注册形如19880431这样的日期。呵呵。 | |
''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = "\u5317\u4eac" | |
s = eval("u'%s'" % s) | |
s.encode('gb18030') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rlcompleter, readline | |
readline.parse_and_bind('tab: complete') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encodin : utf-8 | |
def tostr(s): | |
return "".join(map(lambda c:chr(ord(c)),s)) | |
s = u'\xe4\xbd\xa0\xe5\xa5\xbd' | |
print tostr(s) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment