Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #27424

Re: 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?

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ryniek90@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'package,': 0.03; 'string.': 0.04; '#if': 0.05; 'method.': 0.05; 'processed': 0.05; 'that?': 0.05; 'character,': 0.07; 'column': 0.07; 'function,': 0.07; 'subject:How': 0.09; 'literal': 0.09; 'output,': 0.09; 'res': 0.09; 'subject:characters': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'subject:not': 0.11; 'suggest': 0.11; 'index': 0.13; '"|"': 0.16; '#create': 0.16; '--a': 0.16; 'bars': 0.16; 'owe': 0.16; 'screen,': 0.16; 'subject: \n ': 0.16; 'subject:most': 0.16; 'subject:screen': 0.16; 'wrote:': 0.17; 'pieces': 0.17; 'string,': 0.17; 'thanks,': 0.18; 'solution.': 0.18; 'code,': 0.18; 'skip:p 30': 0.20; 'meant': 0.21; 'together.': 0.21; 'produces': 0.22; "i've": 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'cc:addr:gmail.com': 0.27; 'first,': 0.27; 'cc:2**2': 0.27; 'replace': 0.27; 'character.': 0.29; 'index,': 0.29; 'loop,': 0.29; 'spaces': 0.29; 'strings,': 0.29; 'case,': 0.29; 'character': 0.29; "skip:' 10": 0.30; 'filled': 0.30; 'relative': 0.30; 'function': 0.30; 'could': 0.32; 'print': 0.32; 'subject: .': 0.33; 'equal': 0.33; 'produced': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'url:org': 0.36; 'cc:no real name:2**1': 0.36; 'characters': 0.36; 'method': 0.36; 'skip:p 20': 0.36; 'does': 0.37; 'being': 0.37; 'why': 0.37; 'ones': 0.37; 'passed': 0.37; 'previous': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'description': 0.39; 'space': 0.39; 'list,': 0.39; 'skip:" 10': 0.40; 'your': 0.60; 'most': 0.61; 'you.': 0.61; 'subject:, ': 0.61; 'first': 0.61; 'side': 0.61; 'making': 0.64; 'here': 0.65; 'finally': 0.66; 'combining': 0.71; 'score': 0.75; 'yourself': 0.77; 'bar)': 0.84; 'console,': 0.84; 'experiment': 0.84; 'join,': 0.84; 'nice,': 0.84; 'received:209.85.213.184': 0.91; 'received:mail- yx0-f184.google.com': 0.91; 'angel': 0.93
Newsgroups comp.lang.python
Date Sun, 19 Aug 2012 12:25:35 -0700 (PDT)
In-Reply-To <mailman.3510.1345397520.4697.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=89.231.125.162; posting-account=igkU0woAAAC8IxhDwc4Ves5KfH9PcQQY
References <db49919e-9c9f-4e1f-8dfe-2765c6717dbe@googlegroups.com> <mailman.3510.1345397520.4697.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 89.231.125.162
MIME-Version 1.0
Subject Re: 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?
From crispy <ryniek90@gmail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org, crispy <ryniek90@gmail.com>, d@davea.name
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.3524.1345404343.4697.python-list@python.org> (permalink)
Lines 163
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1345404343 news.xs4all.nl 6980 [2001:888:2000:d::a6]:38319
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:27424

Show key headers only | View raw


W dniu niedziela, 19 sierpnia 2012 19:31:30 UTC+2 użytkownik Dave Angel napisał:
> On 08/19/2012 12:25 PM, crispy wrote:
> 
> > <SNIP>
> 
> > 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.
> 
> 
> 
> rjust() does not print to the console, it just produces a string.  So if
> 
> you want to know how it works, you need to either read about it, or
> 
> experiment with it.
> 
> 
> 
> Try   help("".rjust)     to see a simple description of it.  (If you're
> 
> not familiar with the interactive interpreter's help() function, you owe
> 
> it to yourself to learn it).
> 
> 
> 
> Playing with it:
> 
> 
> 
> print "abcd".rjust(8, "-")       produces    ----abcd
> 
> 
> 
> for i in range(5): print "a".rjust(i, "-")
> 
>     produces:
> 
> 
> 
> a
> 
> a
> 
> -a
> 
> --a
> 
> ---a
> 
> 
> 
> In each case, the number of characters produced is no larger than i.  No
> 
> consideration is made to other strings outside of the literal passed
> 
> into the method.
> 
> 
> 
> 
> 
> > Why it works like that? 
> 
> 
> 
> In your code, you have the rjust() method inside a loop, inside a join,
> 
> inside a print.  it makes a nice, impressive single line, but clearly
> 
> you don't completely understand what the pieces are, nor how they work
> 
> together.  Since the join is combining (concatenating) strings that are
> 
> each being produced by rjust(), it's the join() that's making this look
> 
> "relative" to you.
> 
> 
> 
> 
> 
> > What builtn-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.
> 
> 
> 
> If you want to randomly place characters on the screen, you either want
> 
> a curses-like package, or a gui.  i suspect that's not at all what you want.
> 
> 
> 
> if you want to randomly change characters in a pre-existing string,
> 
> which will then be printed to the console, then I could suggest an
> 
> approach (untested)
> 
> 
> 
> res = [" "] * length
> 
> for column in similarity:
> 
>     res[column] = "|"
> 
> res = "".join(res)
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> 
> 
> DaveA

Thanks, i've finally came to solution.

Here it is -> http://codepad.org/Q70eGkO8

def pairwiseScore(seqA, seqB):

    score = 0
    bars = [str(' ') for x in seqA] #create a list filled with number of spaces equal to length of seqA string. It could be also seqB, because both are meant to have same length
    length = len(seqA)
    similarity = []

    for x in xrange(length):

        if seqA[x] == seqB[x]: #check if for every index 'x', corresponding character is same in both seqA and seqB strings
            if (x >= 1) and (seqA[x - 1] == seqB[x - 1]): #if 'x' is greater than or equal to 1 and characters under the previous index, were same in both seqA and seqB strings, do..
                score += 3
                similarity.append(x)
            else:
                score += 1
                similarity.append(x)                
        else:
            score -= 1

    for x in similarity:
        bars[x] = '|' #for every index 'x' in 'bars' list, replace space with '|' (pipe/vertical bar) character 

    return ''.join((seqA, '\n', ''.join(bars), '\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')

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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? crispy <ryniek90@gmail.com> - 2012-08-19 09:25 -0700
  Re: 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? crispy <ryniek90@gmail.com> - 2012-08-19 09:35 -0700
  Re: 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? Dave Angel <d@davea.name> - 2012-08-19 13:31 -0400
    Re: 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? crispy <ryniek90@gmail.com> - 2012-08-19 12:25 -0700
    Re: 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? crispy <ryniek90@gmail.com> - 2012-08-19 12:25 -0700
      Re: 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? Peter Otten <__peter__@web.de> - 2012-08-20 14:45 +0200
  Re: 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? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-19 14:56 -0400

csiph-web