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

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

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

php - Cloud9 cloud IDE and CakePHP -