Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8407871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:29:14+00:00 2026-06-09T23:29:14+00:00

How does .rjust() work and why it places characters relative to previous one, not

  • 0

How does .rjust() work and why it places characters relative to previous one, not to first character – placed most to left – or to left side of screen?

I have an example:

def pairwiseScore(seqA, seqB):
    prev = -1
    score = 0
    length = len(seqA)
    similarity = []
    relative_similarity = []

    for x in xrange(length):

            if seqA[x] == seqB[x]:
                    if (x >= 1) and (seqA[x - 1] == seqB[x - 1]):
                            score += 3
                            similarity.append(x)
                    else:
                            score += 1
                            similarity.append(x)
            else:
                    score -= 1

    for x in similarity:

            relative_similarity.append(x - prev)
            prev = x

    return ''.join((seqA, '\n', ''.join(['|'.rjust(x) for x in relative_similarity]), '\n', seqB, '\n', 'Score: ', str(score)))


print pairwiseScore("ATTCGT", "ATCTAT"), '\n', '\n', pairwiseScore("GATAAATCTGGTCT", "CATTCATCATGCAA"), '\n', '\n', pairwiseScore('AGCG', 'ATCG'), '\n', '\n', pairwiseScore('ATCG', 'ATCG')

which returns:

ATTCGT

||     |

ATCTAT

Score: 2


GATAAATCTGGTCT

 ||  |||  |

CATTCATCATGCAA

Score: 4

AGCG

| ||

ATCG

Score: 4

ATCG

||||

ATCG

Score: 10

But I created this with some help from one person. Earlier, this code was devoided of these few lines:

prev = -1
relative_similarity = []


for x in similarity:

    relative_similarity.append(x - prev)
    prev = x

The method looked like this:

def pairwiseScore(seqA, seqB):

    score = 0
    length = len(seqA)
    similarity = []

    for x in xrange(length):

            if seqA[x] == seqB[x]:
                    if (x >= 1) and (seqA[x - 1] == seqB[x - 1]):
                            score += 3
                            similarity.append(x)
                    else:
                            score += 1
                            similarity.append(x)
            else:
                    score -= 1

    return ''.join((seqA, '\n', ''.join(['|'.rjust(x) for x in similarity]), '\n', seqB, '\n', 'Score: ', str(score)))

and produced this output:

ATTCGT

||    |

ATCTAT

Score: 2

GATAAATCTGGTCT

| |    |     |      |         |

CATTCATCATGCAA

Score: 4


AGCG

| |  |

ATCG

Score: 4


ATCG

|| |  |

ATCG

Score: 10

So I have guessed, that characters processed by .rjust() function, are placed in output, relative to previous ones – NOT to first, most to left placed, character.
Why it works like that? What built-in function can format output, to make every character be placed as i need – relative to the first character, placed most to left side of screen.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:29:16+00:00Added an answer on June 9, 2026 at 11:29 pm

    str.rjust() doesn’t place anything anywhere; it returns a completely new string containing the old one plus padding on the left side. If you want to put more or less padding due to other text that may appear in the final location then it is your problem to make sure that you use less padding. Perhaps you should consider deferring adding the padding until the output stage, so that it can add the correct amount instead.

    print '%-20s%20s' % ('foo', 'bar')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does doxygen doesn't work properly on python script with a shebang? I tried one
Does the G'MIC (Grey's Magic Image Converter) library work on iOS ? what steps
Does anyone know how I can implement a single Touch Event. A simple, one
Does any one have a solution to make the SpecFlow autocomplete in Visual Studio
Does AtomicInteger provide any kind of fairness guarantee? like first-come-first-serve execution order of threads
Does NSArray shift its elements down if you delete the first element (similar to
Does anyone know how to get IntelliSense to work reliably when working in C/C++
Does anyone use have a good regex library that they like to use? Most
Does it make more sense to loop through each email or to send one
Does any one know of a good tutorial, or jQuery plugin i can use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.