这是在 python 中找出特定名称在字符串中连续出现多少次的正确方法吗
Is this a correct way in python to find out the that a specific name is in the string for how many max no of times continously
用于查找连续没有次数的特定名称的程序。例如'yaweryaweryaweraliyawer'这里的yawer是连续最多3次。
##Created a string to checking for a specific name successive no of times.
string = 'yaweraliyaweryaweryawer'
##this is the name to find
name = 'yawer'
##max no of times name is in the string
count = string.count(name)
##reverse loop for checking
for i in range(count,0,-1):
if name * count in string:
print(f"No of successive times {name} is in string is : {count})
break;
你快到了,只需用计数器删除 name*count "i"
像这样:
for i in range(count,0,-1):
if name * i in string:
print(f"No of successive times {name} is in string is : {i}")
break;
用于查找连续没有次数的特定名称的程序。例如'yaweryaweryaweraliyawer'这里的yawer是连续最多3次。
##Created a string to checking for a specific name successive no of times.
string = 'yaweraliyaweryaweryawer'
##this is the name to find
name = 'yawer'
##max no of times name is in the string
count = string.count(name)
##reverse loop for checking
for i in range(count,0,-1):
if name * count in string:
print(f"No of successive times {name} is in string is : {count})
break;
你快到了,只需用计数器删除 name*count "i"
像这样:
for i in range(count,0,-1):
if name * i in string:
print(f"No of successive times {name} is in string is : {i}")
break;