samedi 28 mars 2015

How to repeat characters in Python without string concatenation?

I'm currently writing a short program that does frequency analysis. However, there's one line that is bothering me:



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


Is there a way in Python to repeat certain characters an arbitrary number of times without resorting to concatenation (preferably inside a format string)? I don't feel like I'm doing this in the most Pythonic way.


Aucun commentaire:

Enregistrer un commentaire