Skip to content

Instantly share code, notes, and snippets.

@prat0318
Last active December 27, 2015 19:19
Show Gist options
  • Save prat0318/7376724 to your computer and use it in GitHub Desktop.
Save prat0318/7376724 to your computer and use it in GitHub Desktop.
Beautification EDIT: small fix: distributing last buffer among all
string = "Hellooooooooooooooooooooooooo thiss is an example of the project to justify the code and we want a biggggggg word also."
l=25
start=0
length = len(string)
while(len(string[start:]) > l):
line = string[start:start+l]
if line.find(' ') == -1:
print line
start = start+l
else:
space_last = line.rfind(' ')
line = line[:space_last]
vacancy = l - space_last
spaces_total = line.count(' ')
if spaces_total == 0:
print line
else:
increase = vacancy/spaces_total
last_increase = vacancy%spaces_total
bline = (" "*(increase+2)).join(line.split(' ')[:last_increase+1])
print bline+" "*(increase+1)+(" "*(increase+1)).join(line.split(' ')[last_increase+1:])
start = start + space_last + 1
print string[start:]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment