相关疑难解决方法(0)

如何将打印输出或字符串格式化为固定宽度?

我有这个代码(在字符串中打印所有排列的出现)

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));
Run Code Online (Sandbox Code Playgroud)

我想打印字符串变量中的所有排列事件.

因为排列不是相同的长度我想要修复宽度并打印出一个不喜欢这个的好处:

value   a - num of occurrences =    1
value   ab - num of occurrences =    1 …
Run Code Online (Sandbox Code Playgroud)

python format python-2.7

93
推荐指数
7
解决办法
21万
查看次数

标签 统计

format ×1

python ×1

python-2.7 ×1