python學習筆記-2.字符串分割

空格分割

s='avg / total       0.91      0.87      0.87        92'
filter(None, s.split(' '))
[out]
['avg', '/', 'total', '0.91', '0.87', '0.87', '92']

字符串轉換

s='LDA_fft_meanlog_lowcut0.1highcut180nfreq_bands8win_length_sec30stride_sec30'
ss=s.replace('LDA_fft_meanlog_lowcut0.1highcut180','')
print ss
replace_dics={'LDA_fft_meanlog_lowcut0.1highcut180':'','nfreq_bands':'B:','win_length_sec':'_W:','stride_sec':'_L:'}
for it in replace_dics:
    s=s.replace(it,replace_dics[it])
print s
[out]:
nfreq_bands8win_length_sec30stride_sec30
B:8_W:30_L:30
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章