Skip to content

Instantly share code, notes, and snippets.

@dxlbnl
Created March 26, 2013 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dxlbnl/5245302 to your computer and use it in GitHub Desktop.
Save dxlbnl/5245302 to your computer and use it in GitHub Desktop.
resp_lines = [
str(range(i)) for i in range(20, 50,3)
]
width = 80
space = " "
"""
The proper way ?
"""
new_resp_lines = []
for line in resp_lines:
_space = ''
lns = []
if len(line) > width:
while len(line) > (width - len(_space)):
lns.append(_space + line[:(width - len(_space))])
line = line[(width - len(_space)):]
_space = space
lns.append(_space + line)
new_resp_lines += lns
else:
new_resp_lines.append(line)
"""
The improper way ?
"""
for i, line in enumerate(resp_lines):
if len(line) > width:
resp_lines[i:i+1] = [
line[0:width],
space + line[width:]
]
print '\n'.join(new_resp_lines)
print "_______"
print '\n'.join(resp_lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment