Skip to content
Advertisement

Align strings over a common character

I am looking for a simple, pythonic way of doing this with the minimum calculations and loops.

I have a bunch of strings, such as:

JavaScript

What I would like to print at the screen is:

JavaScript

(where the x are actually spaces, but I could not figure out how to show it with this editor)

I am aware of string formatting with left and right align but this imply for each string to compute the number of spaces to add, convert it into a string, and inject this into the string alignment formatter, which seems complex.

Is there a simpler way?

Advertisement

Answer

Based on the information you provided, this may work:

JavaScript

Output

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement