Created
November 2, 2016 09:21
-
-
Save thekoc/6b5ee421a0727cd0ef4b3909de05f990 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lines = """I am happy to join with you today in what will go down in history as the greatest demonstration for freedom in the history of our nation. | |
Five score years ago, a great American, in whose symbolic shadow we stand today, signed the Emancipation Proclamation. This momentous decree came as a great beacon light of hope to millions of Negro slaves who had been seared in the flames of withering injustice. It came as a joyous daybreak to end the long night of their captivity.""" | |
def wrap_line(tokens): | |
if len(' '.join(tokens)) <= 80: | |
return ' '.join(tokens) | |
for i in range(len(tokens)): | |
if len(' '.join(tokens[:i+1])) > 80: | |
return ' '.join(tokens[:i]) + '\n' + wrap_line(tokens[i:]) | |
wrapped = '\n'.join([wrap_line([t for t in line.split()]) for line in lines.splitlines()]) | |
print(wrapped) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment