Created
June 8, 2016 20:36
-
-
Save kissgyorgy/edc7204bbf549b62445921448337511e to your computer and use it in GitHub Desktop.
Python: leftpad without stdlib
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
def leftpad(string, length): | |
if len(string) >= length: | |
return string | |
spaces_to_add = length - len(string) | |
return ' ' * spaces_to_add + string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment