count (), a list of derivation formula, transpose ()

count () function to derive a list of the formula

In [85]:
The number of occurrences of the word # statistics for each element specified in the list
words=['apple','pare','banana','and','peach','Anda']
for word in words:
    Print ( Word. Lower (). COUNT ( 'A')) #lower () is case-sensitive
1
1
3
1
1
2
In [86]:
  [ word for word in words if word.lower().count('a')>=2]
 
 
Out[86]:
[ 'Banana', 'you']
In [69]:
strings=['a','bv','tit','apple','ctr']
[x.title() for x in strings if len(x)>2]
 
 
Out[69]:
['Tit', 'Apple', 'Ctr']
In [74]:
list(map(len,strings))
  
Out[74]:
[1, 2, 3, 5, 3]
 

TRANSPOSE () transpose

In [88]:
import numpy as np
three=np.arange(18).reshape(2,3,3)
 
In [89]:
three
 
Out[89]:
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],

       [[ 9, 10, 11],
        [12, 13, 14],
        [15, 16, 17]]])
In [97]:
 
three.transpose(2,1,0)
Out[97]:
array([[[ 0,  9],
        [ 3, 12],
        [ 6, 15]],

       [[ 1, 10],
        [ 4, 13],
        [ 7, 16]],

       [[ 2, 11],
        [ 5, 14],
        [ 8, 17]]])
 

Guess you like

Origin www.cnblogs.com/liyun1/p/11261867.html