Skip to content

Instantly share code, notes, and snippets.

@mattstibbs
Created April 30, 2014 18:47
Show Gist options
  • Save mattstibbs/72c69738e382424d08e9 to your computer and use it in GitHub Desktop.
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)
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