r=re.compile(r'\d+')
array=r.findall('134 56 8899 99')
b=[]
for no in array:
b.append(int(no))
b.sort()
for no in b:
print no
import re
r=re.compile(r'[^a-zA-Z]')
first_last = re.compile(r'>(.+?)\n([^>]+)', re.S)
for name,gene in first_last.findall(open('1.txt').read( )):
print ">"+name
print 10*"||||"
print r.sub('', gene,0)
print 10*"---"
digs = re.compile(r'\d+')
for line in open('1.txt'):
if digs.match(line):
print line
print 10*"---"
for line in open('1.txt'):
for num in digs.findall(line):
print num
print 10*"++"
pat=r'(abc):(123)4(56)'
r=re.compile(pat)
s='aaabc:123456defghikabc:123456lll'
for a in r.split(s):
print a
astring = ''.join(r.split(s, 1))
print astring
r=re.compile(r'[^a-zA-Z]')
str='aa45 adf3477hh 66 ttt56'
newstr=r.sub('', str,0)
print newstr
h_word = re.compile(r'\bh\w+o\b', re.IGNORECASE)
def up(mo):
return mo.group(0).upper()+"-xie"
astring=" hlladfl0 hasde tthadfo hasdfo asdf"
print h_word.sub(up, astring)
rehello = re.compile(r'hello', re.IGNORECASE)
astring="adfashelloasdfhello hello xx"
junk, count = rehello.subn('', astring)
print junk
print 'Found', count, 'occurrences of "hello"'
h_word = re.compile(r'[AGCT]', re.IGNORECASE)
def XXX(mo):
if mo.group(0).upper()=='A':
return 'T'
if mo.group(0).upper()=='G':
return 'C'
if mo.group(0).upper()=='C':
return 'G'
if mo.group(0).upper()=='T':
return 'A'
astring="AGCTt"
print h_word.sub(XXX, astring)[::-1]
l = list(s)
l.reverse()
print ''.join(l)
h_word = re.compile(r'([a-zA-Z]+)\d+([a-zA-Z]+)', re.IGNORECASE)
def XXX(mo):
print mo.groups()
return mo.group(1)
astring=" AD56UU ZZ66YY XX66 66UUUU "
print h_word.sub(XXX, astring)
aa="\d+"
h_word = re.compile(r''+aa+'', re.IGNORECASE)
astring=" AD56UU zzyy ZZ66YY XX66 66UUUU "
print h_word.sub('', astring)
#a=['xx xx ','yy','zz','tt']
#b=["mm","ff"]
#a.append("yy")
#print a.count("yy")
#a.extend(b)
#a.pop(0)
#for r in a:
# print r
b=['xx','mm','aa','kkk' ]
b.sort()
print b
dict={}
dict['xx']=2
dict['mm']=3
dict['yy']=6
dict['aa']=9
a=dict.keys()
a.sort
for r in a:
print r+" "+str(dict[r])
sampledict_str = {'blue':'5555@sina.com',
'allen':'222@163.com',
'sophia':'4444@gmail.com',
'ceen':'blue@263.net'}
print sampledict_str
print "\n";
# 按照key进行排序
print sorted(sampledict_str.items(), key=lambda d: d[0])
# 按照value进行排序
print sorted(sampledict_str.items(), key=lambda d: d[1])
s = {'blue':'5555@sina.com',
'allen':'222@163.com',
'sophia':'4444@gmail.com',
'ceen':'blue@263.net'}
a=s.keys().sort()
file=open("xx.out","w")
print >>file, "xxxx"
print >>file, "zzzz"
print >>file, "hhhh"
file.close()
file=open("xx.out","r")
records=file.readlines()
for record in records:
print record.strip()
file=open("xx.out","r")
file.write("xxx\nyyy\ntttt\n")
file.close()
file.read()
file=open("xx.out","r")
str=file.read(file.__sizeof__())
print str
import MySQLdb
conn=MySQLdb.connect(host="localhost",user="root",passwd="",db="mirbase")
cursor=conn.cursor()
cursor.execute("select auto_mirna, mirna_acc from mirna")
cds = cursor.fetchall()
for row in cds:
print str(row[1]).strip()
values=[]
#生成插入参数值
for i in range(20):
values.append((i,'Hello mysqldb, I am recoder ' + str(i)))
#插入多条记录
cursor.executemany("""insert into test values(%s,%s) """,values);
conn.commit()
query = "insert into xx (age,name) values(%s,%s)"
param = ("1","xxx")
cursor.execute(query,param)
评论