optimize
This commit is contained in:
parent
d338c55b1c
commit
e6221a7f28
1 changed files with 2 additions and 2 deletions
|
@ -69,17 +69,17 @@ def wrapString(string, length=80, separator='\n', balance=False):
|
||||||
>>> wrapString('All you can eat', 12, '\n', True)
|
>>> wrapString('All you can eat', 12, '\n', True)
|
||||||
'All you \ncan eat'
|
'All you \ncan eat'
|
||||||
'''
|
'''
|
||||||
|
words = string.split(' ')
|
||||||
if balance:
|
if balance:
|
||||||
# balance lines: test if same number of lines
|
# balance lines: test if same number of lines
|
||||||
# can be achieved with a shorter line length
|
# can be achieved with a shorter line length
|
||||||
lines = wrapString(string, length, separator, False).split(separator)
|
lines = wrapString(string, length, separator, False).split(separator)
|
||||||
if len(lines) > 1:
|
if len(lines) > 1:
|
||||||
while length > max(map(lambda x : len(x), string.split(' '))):
|
while length > max(map(lambda x : len(x), words)):
|
||||||
length -= 1
|
length -= 1
|
||||||
if len(wrapString(string, length, separator, False).split(separator)) > len(lines):
|
if len(wrapString(string, length, separator, False).split(separator)) > len(lines):
|
||||||
length += 1
|
length += 1
|
||||||
break
|
break
|
||||||
words = string.split(' ')
|
|
||||||
lines = ['']
|
lines = ['']
|
||||||
for word in words:
|
for word in words:
|
||||||
if len(lines[len(lines) - 1] + word + ' ') <= length + 1:
|
if len(lines[len(lines) - 1] + word + ' ') <= length + 1:
|
||||||
|
|
Loading…
Reference in a new issue