Created
April 30, 2014 18:47
-
-
Save mattstibbs/72c69738e382424d08e9 to your computer and use it in GitHub Desktop.
Look through a string for UK number plates with a space in the middle, and combine them into a single word (e.g. AB12 GHF -> AB12GHF, J586 GHH -> J586GHH)
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 combinesplitregistrations(message): | |
def contains_digits(s): | |
return any(char.isdigit() for char in s) | |
f = message | |
words = message.split(" ") | |
newwords = [] | |
totalwords = len(words) | |
e = 0 | |
while e < totalwords: | |
thisword = words[e] | |
if len(thisword) < 5 and contains_digits(thisword) and e < (totalwords-1) and len(thisword[e+1]) < 4: | |
e += 1 | |
newwords.append(thisword + words[e]) | |
else: | |
newwords.append(words[e]) | |
e += 1 | |
return newwords |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment