How to repeat characters in Python without string concatenation? -


i'm writing short program frequency analysis. however, there's 1 line bothering me:

"{0[0]}  | " + "[]" * num_occurrences + " total: {0[1]!s}" 

is there way in python repeat characters arbitrary number of times without resorting concatenation (preferably inside format string)? don't feel i'm doing in pythonic way.

the best way repeat character or string multiply it:

>>> "a" * 3 'aaa' >>> '123' * 3 '123123123' 

and example, i'd use:

>>> "{0[0]}  | {1} total: {0[1]!s}".format(foo, "[]" * num_occurrences) 

Comments

Popular posts from this blog

angularjs - Showing an empty as first option in select tag -

qt - Change color of QGraphicsView rubber band -

c++ - Visible files in the "Projects" View of the Qt Creator IDE if using the CMake build system -