Created
September 20, 2019 14:18
-
-
Save gpprojekt-marcin/28bd08a7eb1f5abef84fa6f6f685d09d to your computer and use it in GitHub Desktop.
Python break string in the middle space
This file contains 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 FindLabel ( [NAZWA_OBIEKTU] ): | |
label = [NAZWA_OBIEKTU] | |
if (label.count('-') != 0): | |
return '\n'.join([e.strip() for e in label.split('-')]) | |
lens=[n for n in range(len(label)) if label.find(' ', n) == n] | |
abss = [abs(round(len(label)/2)-e) for e in lens] | |
i=lens[abss.index(min(abss))] | |
return '\n'.join([label[:i].strip(),label[i:].strip()]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment