Skip to content

Instantly share code, notes, and snippets.

@qingfeng
Created August 21, 2008 15:23
Show Gist options
  • Save qingfeng/6578 to your computer and use it in GitHub Desktop.
Save qingfeng/6578 to your computer and use it in GitHub Desktop.
python tips
>>> 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')]
>>> def func(a,b,c):
... print a,b,c
...
>>> func(*[1,2,3])
1 2 3
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这样的日期。呵呵。
'''
s = "\u5317\u4eac"
s = eval("u'%s'" % s)
s.encode('gb18030')
import rlcompleter, readline
readline.parse_and_bind('tab: complete')
# 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