学python需要什么配置的电脑-python用什么配置电脑python 计算子字符串的数量

#coding=utf-8

def countSubStr(str1):

dict1 = {}

list1 = []

s_len = len(str1) + 1

if s_len<2:

return dict;

for i in range(0,s_len):

for j in range(i+2,s_len):

list1.append(str1[i:j])

for s in list1:

# print('%s-%s' % (s,list1.count(s)))

dict1.setdefault(s,list1.count(s)) # 去重

return dict1

res = countSubStr('abcabcd')

002pc.com从python用什么配置电脑python 计算子字符串的数量分析来看,对python用什么配置电脑python 计算子字符串的数量的结果。

print(res)

res = countSubStr('abc')

print(res)

结果:

{'ab': 2, 'abc': 2, 'abca': 1, 'abcab': 1, 'abcabc': 1, 'abcabcd': 1, 'bc': 2, 'bca': 1, 'bcab': 1, 'bcabc': 1, 'bcabcd': 1, 'ca': 1, 'cab': 1, 'cabc': 1, 'cabcd': 1, 'abcd': 1, 'bcd': 1, 'cd': 1}

{'ab': 1, 'abc': 1, 'bc': 1}

另一版:

#coding=utf-8

sString = 'abcabcd'

len = len(sString)

list = []

list1 = []

i = 0

if len <= 1 :

print("")

else:

while (i <= len):

j = i+2

while (j <= len):

list.append(sString[i:j])

if sString[i:j] not in list1:

list1.append(sString[i:j])

j += 1

i += 1

print (list1)

for k in list1:

print(k,list.count(k))

更多:python用什么配置电脑python 计算子字符串的数量

https://www.002pc.comhttps://www.002pc.com/python/2031.html

你可能感兴趣的python,字符串,计算,数量

No alive nodes found in your cluster

0踩

0 赞

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值