我有这个代码(在字符串中打印所有排列的出现)
def splitter(str):
for i in range(1, len(str)):
start = str[0:i]
end = str[i:]
yield (start, end)
for split in splitter(end):
result = [start]
result.extend(split)
yield result
el =[];
string = "abcd"
for b in splitter("abcd"):
el.extend(b);
unique = sorted(set(el));
for prefix in unique:
if prefix != "":
print "value " , prefix , "- num of occurrences = " , string.count(str(prefix));
我想打印字符串变量中的所有排列事件.
因为排列不是相同的长度我想要修复宽度并打印出一个不喜欢这个的好处:
value a - num of occurrences = 1
value ab - num of occurrences = 1
value abc - num of occurrences = 1
value b - num of occurrences = 1
value bc - num of occurrences = 1
value bcd - num of occurrences = 1
value c - num of occurrences = 1
value cd - num of occurrences = 1
value d - num of occurrences = 1
我该如何使用格式呢?
我找到了这些帖子,但是它与字母数字字符串不相符: