'Need to know if a value contain 3 letters and 3 numbers
I am working with car plate data from my country and I need to check if there is a plate misspelled. The current and correct form is with three letters and three numbers (AAA000), but I saw values like one letter or all numbers. So far I am only capable to know if it is all numbers or letters. Sorry I have no code to share, I'm still too noob.

Solution 1:[1]
Supose plate is a list, you can do it with regex:
>>> import re
>>> plates = ['000003', 'TPU553', 'TPU374', 'SVM978']
>>> list(filter(lambda x : re.match(r'\D{3}\d{3}',x),plates))
['TPU553', 'TPU374', 'SVM978']
Solution 2:[2]
This function must resolve your problem:
df["Placa"].apply(lambda x: True if x[:3].isalpha() and x[3:].isdigit() and len(x) == 6 else False)
Solution 3:[3]
This is my take on your question. Made a function that checks if the 3 first characters are letter and so on with the next 3 characters.
def checkcarplate(carplate):
for i in range(len(carplate)):
if i<3:
if not carplate[i].isalpha():
print('error')
break
elif i>2:
if not carplate[i].isdigit():
print('error')
break
elif i==len(carplate)-1:
print('ok')
carplate="A1C123"
checkcarplate(carplate)
carplate="ABC123"
checkcarplate(carplate)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jonatrios |
| Solution 2 | Ítalo De Pontes Oliveira |
| Solution 3 |
