Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等

Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
s.strip() .lstrip() .rstrip(',') 去空格及特殊符号

复制字符串

Python

1 #strcpy(sStr1,sStr2)
2 sStr1 = 'strcpy'
3 sStr2 = sStr1
4 sStr1 = 'strcpy2'
5 print sStr2

连[……]

Read more

[…]

Python 自建标准差函数

def stdDeviation(a): l=len(a) m=sum(a)/l d=0 for i in a: d+=(i-m)**2 return (d*(1/l))**0.5 a=[5,6,8,9] print(stdDeviation(a)) ======== 1.5811388300841898 […]

[python] 关于python中的string.atoi()的问题

#!/usr/bin/python #filename:string.py import string print  string.atoi(’13’,8)      #这里转换8进制的数 print string.atoi(’13’,16)     #这里转换成16进制的数 运行后的结果: 11 19     >>> import string >>> string.atoi(’13’,8) 11 >>> string.atoi(’13’,10) 13 >>> string.at[……]

Read more

[…]

python 正则表达 前向界定与后向界定

>>> a ‘[acyl-carrier-protein] S-malonyltransferase [EC:2.3.1.39]’ >>> b = re.findall(r'(?<=\[EC:).+?(?=\])’,a) >>> b [‘2.3.1.39′] >>> b = re.findall(r'(?<=\[).+?(?=\])’,a) >>> b [‘acyl-carrier-protein’, ‘EC:2.3.1.39′]    前向界定与后向界定 有时候需要[……]

Read more

[…]

python dic problem

dic_cog_annot[h2[1]]={‘orthologous_group':h[3]} dic_cog_annot[h2[1]][‘protein_annot’]=h[4] 以上是增加个protein_annot键值, 如果是以下,将会被替换,只一个键值! dic_cog_annot[h2[1]]={‘orthologous_group':h[3]} dic_cog_annot[h2[1]]={‘protein_annot':h[4]}   dic[name]=”NA” dic[name] = {‘nr_annot':”NA”} dic[[……]

Read more

[…]

python 键值排序输出

method1: dic = {} keys= dic.keys() keys.sort() for key in keys: print dic[key]   method2: for key in sorted(write_list_hash.keys()): print write_list_hash[key] […]

ACEAssemblySplitter.py

#! /usr/bin/env python2.7 desc = """ Split an ACE format assembly file into multiple single ACE files each with a single contig. The resulting ACE contig files are formatted so that they can be read by CodonCode (http://www.codoncode.com). $ ACEAssemblySplitter.py test.ace -s 2 -e[......]

Read more

[…]

python 删除列表空元素或相同元素

a=[‘a’,’b’,’c’,’a’,’d’,’a’] 如何把所有的’a’删除呢? 我的笨方法: for i in a: if i == ‘a': a[a.index(i)] = ” while ” in a: a.remove(”) […]