Commit 56bfb4e 1 parent 521e46a commit 56bfb4e Copy full SHA for 56bfb4e
File tree 1 file changed +7
-10
lines changed
1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change
1
+ import re
1
2
from typing import List
2
3
3
4
from models .middleware import Middleware
6
7
class Number (Middleware ):
7
8
def validate (self , data : List [str ]) -> (List [str ], int ):
8
9
"""
9
- Validate the data and exclude only numbers data.
10
+ validate data and exclude tokens that contain numbers with regex
10
11
11
12
:param data: The data to validate.
12
13
:return: The validated data and the number of errors.
13
14
"""
14
- errors = 0
15
- validated_data = []
16
- for item in data :
17
- try :
18
- int (item )
19
- errors += 1
20
- except ValueError :
21
- validated_data .append (item )
22
- return validated_data , errors
15
+ regex : re .Pattern = re .compile (r'\d' )
16
+
17
+ result = [token for token in data if not regex .match (token )]
18
+
19
+ return result , len (data ) - len (result )
You can’t perform that action at this time.
0 commit comments