count()函数 列表推导式
In [85]:
#统计列表每个元素中指定单词出现的个数
words=['apple','pare','banana','and','peach','Anda']
for word in words:
print(word.lower().count('a')) #lower()识别大小写
In [86]:
[word for word in words if word.lower().count('a')>=2]
Out[86]:
In [69]:
strings=['a','bv','tit','apple','ctr']
[x.title() for x in strings if len(x)>2]
Out[69]:
In [74]:
list(map(len,strings))
Out[74]:
transpose() 转置
In [88]:
import numpy as np
three=np.arange(18).reshape(2,3,3)
In [89]:
three
Out[89]:
In [97]:
three.transpose(2,1,0)
Out[97]: