对参数key使用lambda切割字符串,然后int转化数值进行排序,代码如下:

1
2
3
a = ['gene1', 'gene100', 'gene2', 'gene3', 'gene300']
a.sort(key=lambda x: int(x.split('gene')[1]))
print a
1
['gene1', 'gene2', 'gene3', 'gene100', 'gene300']

sorted()函数同理