python - Display the number of substrings along with the substring
问题描述
The input should be manual and must be able to count the number of substrings for any kind of input and also display them
解决方案
# Function to print all sub strings
def subString(s, n):
# Pick starting point in outer loop
# and lengths of different strings for
# a given starting point
c=0
for i in range(n):
for len in range(i+1,n+1):
print(s[i: len]); #prints substring
c+=1
print("Number of substrings:",c)
# Driver program to test above function
s = "abcd";
subString(s,len(s));
推荐阅读
- python - 在python中打印字符串时的额外间距
- sql - 拥有每个赛季的顶级球队(只有一个)
- python - Python 中的位运算符
- html - 文字和图像重叠?
- reactjs - React App 在 localhost 和 Heroku 中的显示方式不同
- kubernetes - 本地 Kubernetes 上的 Nifi。收到请求类型 GET 的无效密钥
- javascript - 将 toStringTag 与 Object.defineProperties 一起使用时出现意外结果
- scala - 比较数组中的相同案例类数据
- python - 如何分离从python运行的linux命令
- r - 非准引用上下文中的 Tidyeval (psych::describeBy(group))