value = 'bcdjbcdscv'
value = 'bcdvfdvdfvvdfvv'
value = 'bcvfdvdfvcdjbcdscv'
def count_letters(word, char):
count = 0
for c in word:
if char == c:
count += 1
return count
Run Code Online (Sandbox Code Playgroud)
如何计算带有样本列表的字符串中的字母数?当我在python文件中编写上面的代码时,我的python shell中什么都没有.
给定源代码时如何获得年份(4位数),我只能检测到第29天,但无法检测到年份(1997年).我的正则表达式检查有问题.
age = regexp(CharData,'(\d{1,4})','match','once')
Run Code Online (Sandbox Code Playgroud)
例如,
1997年3月29日注册
期望的产出: 1997年
错误输出: 29
for i = 1:2
data2=fopen(strcat('DATA\PRE-PROCESS_DATA\F22_TR\f22_TR_pdata_',int2str(i),''),'r')
CharData = fread(data2, '*char'); %read text file and store data in CharData
fclose(data2);
age = regexp(CharData,'(\d{4})','match','once')
end
Run Code Online (Sandbox Code Playgroud)
file:f22_TR_pdata_1 - > 1997年6月24日注册
档案:f22_TR_pdata_2 - > 1997年3月29日注册
年龄: 1997年