return 0 if X<0.5 else 1
bin = lambda n : (n > 0) and (bin(n/2) + str(n%2)) or ''
bin = lambda x: (bin(x / 2) + str(x % 2)) if x > 0 else ''
计算DNA序列的反向互补序列
print ''.join(["ATCG"["TAGC".index(n)] for n in "ACTGCTCTAGCTAAGCA"[::-1]])
PS:高考像是让我们赴一面之约的情人,我们整装待发,人模人样,心存侥幸,怀揣好意,想显出最优秀的自己,捕获芳心,可是,它终究令人无法爱上,毕竟,这是一场群P!
阶乘
return reduce(lambda a, b : a * b, range(1, x + 1))
9*9乘法表
print ('\n'.join([' '.join(['%s*%s=%-2s'%(y,x,x*y) for y in range(1,x+1)]) for x in range(1,10)]))
获取文件最长的行的长度
print max(len(x.strip()) for x in open('a.txt'))
获取网站标题
print __import__("re").search(r"
用Python实现了JSON
json = lambda s, encoding = sys.getdefaultencoding(): repr(unicode(s, encoding))
字符串排序
print "".join((lambda x:(x.sort(),x)[1])(list('string')))
快速排序
return [] if ls == [] else quick_sort([y for y in ls[1:] if y < ls[0]]) + [ls[0]] + quick_sort([y for y in ls[1:] if y >= ls[0]])
双倍超立方数计算
print len([1 for a in [x+y for x,y in [(k,j) for k in [i3 for i in xrange(int(round(pow(100000, 1./3))))] for j in [i3 for i in xrange(int(round(pow(100000, 1./3))))] if k <= j]] if [x+y for x,y in [(k,j) for k in [i3 for i in xrange(int(round(pow(100000, 1./3))))] for j in [i3 for i in xrange(int(round(pow(100000, 1./3))))] if k <= j]].count(a)==2])/2