Skip to content

Instantly share code, notes, and snippets.

@gpprojekt-marcin
Created September 20, 2019 14:18
Show Gist options
  • Save gpprojekt-marcin/28bd08a7eb1f5abef84fa6f6f685d09d to your computer and use it in GitHub Desktop.
Save gpprojekt-marcin/28bd08a7eb1f5abef84fa6f6f685d09d to your computer and use it in GitHub Desktop.
Python break string in the middle space
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