Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right-to-Left and Left-to-Right printed nicely

I want it to produce the number next to a word so that I can ask the user to select the word by using the corresponding number.

This is my code

alt_words = hlst
loopnum = 8
for i in range(loopnum):
        if i < len(alt_words):
            print('{0}. {1:<20}'.format((i+1), alt_words[i]), end =' ')
            if i == 0:
                print('', end=' ')
        if i + 9 <= len(alt_words):
            print('{0}. {1:<20}'.format((i+9), alt_words[i+8]), end =' ')
        if i + 17 <= len(alt_words):
            print('{0}.  {1:<20}'.format((i+17), alt_words[i+16]), end=' ')
        print('\n'+'-'*80)

It produces this Output from code

The first number of each line gets printed on the left, but the word on the right, while the rest of the numbers and words get printed RTL. It seems that once python has started printing on a line LTR it can switch to RTL, but not back from RTL to LTR. Note how even the periods are printed to the right of the number for the second set of numbers on each line.

It works perfectly well and looks nice with english words:

python table works in english

I am guessing a work around might involve putting the number after the word, but I figure there must be a better way.

like image 943
Seraphya Avatar asked Mar 02 '17 12:03

Seraphya


People also ask

How to check if current row should be printed from left to right?

We maintain a flag to see if current row should be printed from left to right or right to left. We toggle the flag after every iteration. This article is contributed by DANISH_RAZA.

Why does printf not execute from left to right?

There is no such thing. printf does NOT execute from left to right, neither does it execute from right to left. It executes in the order of whatever the compiler likes, by its mood. It can even execute in a random order, if the compiler hates you.

What is an example of left to right alignment?

For example, if you left-align text with content in the left-to-right (LTR) context, right-align the text to match the content’s mirrored position in the RTL context. Align a paragraph based on its language, not on the current context.

What languages are written right to left?

Arabic, Hebrew, Pashto, Urdu, and Sindhi are the most widespread RTL writing systems in modern times. Right-to-left can also refer to top-to-bottom, right-to-left (TB-RL or TBRL) scripts such as Chinese, Japanese, and Korean, though in modern times they are also commonly written left to right.


1 Answers

Put a Right-to-Left Embedding character, u'\u202B', at the beginning of each Hebrew word, and a Pop Directional Formatting character, u'\u202C', at the end of each word.

This will set the Hebrew words apart as RTL sections in an otherwise LTR document.

(Note that while this will produce the correct output, you're also dependent on the terminal application in which you're running this script having implemented the Unicode Bidirectional Algorithm correctly.)

like image 73
kpozin Avatar answered Sep 24 '22 16:09

kpozin