0

I am using the following simple code to tabulate the unicode characters in python3. How ever, for some reasons, the format couldn't come out right for some range of numbers.I appreciate if some one give me hint how to fix it.

equal = " = "
n=5
for i in range(int(1000/n),int(6000/n)):
    for j in range(n):
        print(f'{(n*i+j+1):<5d}{equal}{chr(n*i+j+1):<22s}',end="")
    print()

The spacing is proportional to the length of each string. In this case it is not working.

thanks gor your help.

  • What does "it is not working" mean? What specific output were you expecting, and how does it differ from what you got? – ekhumoro Nov 11 '22 at 14:25
  • Hi ekhumoro: My intention is to print it in 5 coulumns with lefft aligned. Each column has a number and its unicode value. If I print it in one column, it perfectely alligned. The way I did it is it prints row by row. It prints a single row with 5 columns at a time. I suspect the problem is that I do not know the size of each unicode character and not formating accoring to its size. Last time, I also attached a screen shot of the print. I don't know how to do it this time. But you may try it yourself with lowe iterations. – yohan T. Nov 14 '22 at 03:09
  • See this question: [How do you get the display width of combined Unicode characters in Python 3](https://stackoverflow.com/q/30881811/984421). But you're also going to face problems with [LTR *vs* RTL writing systems](https://en.wikipedia.org/wiki/Writing_system#Directionality), amongst other things. It's probably not going to be possible to achieve totally consistent output. – ekhumoro Nov 14 '22 at 05:11

0 Answers0