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: 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: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=89.231.125.162; posting-account=igkU0woAAAC8IxhDwc4Ves5KfH9PcQQY References: 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 To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org, crispy , 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: 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 W dniu niedziela, 19 sierpnia 2012 19:31:30 UTC+2 u=C5=BCytkownik Dave Ange= l napisa=C5=82: > On 08/19/2012 12:25 PM, crispy wrote: >=20 > > >=20 > > So I have guessed, that characters processed by .rjust() function, are = placed in output, relative to previous ones - NOT to first, most to left pl= aced, character. >=20 >=20 >=20 > rjust() does not print to the console, it just produces a string. So if >=20 > you want to know how it works, you need to either read about it, or >=20 > experiment with it. >=20 >=20 >=20 > Try help("".rjust) to see a simple description of it. (If you're >=20 > not familiar with the interactive interpreter's help() function, you owe >=20 > it to yourself to learn it). >=20 >=20 >=20 > Playing with it: >=20 >=20 >=20 > print "abcd".rjust(8, "-") produces ----abcd >=20 >=20 >=20 > for i in range(5): print "a".rjust(i, "-") >=20 > produces: >=20 >=20 >=20 > a >=20 > a >=20 > -a >=20 > --a >=20 > ---a >=20 >=20 >=20 > In each case, the number of characters produced is no larger than i. No >=20 > consideration is made to other strings outside of the literal passed >=20 > into the method. >=20 >=20 >=20 >=20 >=20 > > Why it works like that?=20 >=20 >=20 >=20 > In your code, you have the rjust() method inside a loop, inside a join, >=20 > inside a print. it makes a nice, impressive single line, but clearly >=20 > you don't completely understand what the pieces are, nor how they work >=20 > together. Since the join is combining (concatenating) strings that are >=20 > each being produced by rjust(), it's the join() that's making this look >=20 > "relative" to you. >=20 >=20 >=20 >=20 >=20 > > What builtn-in function can format output, to make every character be p= laced as i need - relative to the first character, placed most to left side= of screen. >=20 >=20 >=20 > If you want to randomly place characters on the screen, you either want >=20 > a curses-like package, or a gui. i suspect that's not at all what you wa= nt. >=20 >=20 >=20 > if you want to randomly change characters in a pre-existing string, >=20 > which will then be printed to the console, then I could suggest an >=20 > approach (untested) >=20 >=20 >=20 > res =3D [" "] * length >=20 > for column in similarity: >=20 > res[column] =3D "|" >=20 > res =3D "".join(res) >=20 >=20 >=20 >=20 >=20 >=20 >=20 > --=20 >=20 >=20 >=20 > DaveA Thanks, i've finally came to solution. Here it is -> http://codepad.org/Q70eGkO8 def pairwiseScore(seqA, seqB): score =3D 0 bars =3D [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 =3D len(seqA) similarity =3D [] for x in xrange(length): if seqA[x] =3D=3D seqB[x]: #check if for every index 'x', correspon= ding character is same in both seqA and seqB strings if (x >=3D 1) and (seqA[x - 1] =3D=3D seqB[x - 1]): #if 'x' is = greater than or equal to 1 and characters under the previous index, were sa= me in both seqA and seqB strings, do.. score +=3D 3 similarity.append(x) else: score +=3D 1 similarity.append(x) =20 else: score -=3D 1 for x in similarity: bars[x] =3D '|' #for every index 'x' in 'bars' list, replace space = with '|' (pipe/vertical bar) character=20 return ''.join((seqA, '\n', ''.join(bars), '\n', seqB, '\n', 'Score: ',= str(score))) print pairwiseScore("ATTCGT", "ATCTAT"), '\n', '\n', pairwiseScore("GATAAAT= CTGGTCT", "CATTCATCATGCAA"), '\n', '\n', pairwiseScore('AGCG', 'ATCG'), '\n= ', '\n', pairwiseScore('ATCG', 'ATCG')