This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author LambertDW
Recipients LambertDW, akuchling, andybuckley
Date 2009-02-26.14:46:07
SpamBayes Score 6.082062e-09
Marked as misclassified No
Message-id <1235659569.76.0.503209793603.issue4318@psf.upfronthosting.co.za>
In-reply-to
Content
I'd like textwrap option to preserve new lines.  Actual case:

I have a code that produces cryptograms meant to be printed and solved 
with paper and pencil.  Standard format for cryptogram inserts space 
character between each character of the original text, doubling the line 
length.  textwrap is handy to fit the cryptogram back to paper width.

Problem: When text to "cryptogramize" is a limerick original line breaks 
should be preserved.


P A Y C Y   H J K   J   K Q L Z   B J U R   G C V F   P C Y I P ,   H A 
V 

 K V O N A P   I Y H   H J R K   P V   U Y U Y I P .   A Y C   P R E ' Y 
C 

 L A V L Z   G O B B   V G   E V V   G C V F   J   N O B B .   K A Y 

 U Q Y U   B J K P   I Q N A P ;   K A Y   H J K   K E Y I P . 

 J I V I R F V O K



import string
import random
import textwrap

def Shuffle(L):
    random.shuffle(L)
    return L

def create_cryptogram(quote):
    """
        (disregards cryptogram rule that a letter can't stand for 
itself)
	doctest omitted
    """
    # wish: wrap line-by-line to preserve original line breaks
    wrapped_quote = textwrap.fill(text=quote,width=38).upper()
    d = {c:c for c in string.printable}
    d['\n'] = '\n'*2
    UC = string.ascii_uppercase
    d.update(zip(UC,Shuffle(list(UC))))
    return ' '.join(d[c] for c in wrapped_quote)
History
Date User Action Args
2009-02-26 14:46:09LambertDWsetrecipients: + LambertDW, akuchling, andybuckley
2009-02-26 14:46:09LambertDWsetmessageid: <1235659569.76.0.503209793603.issue4318@psf.upfronthosting.co.za>
2009-02-26 14:46:08LambertDWlinkissue4318 messages
2009-02-26 14:46:07LambertDWcreate