-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathRegexMap.py
More file actions
executable file
·54 lines (42 loc) · 1.21 KB
/
RegexMap.py
File metadata and controls
executable file
·54 lines (42 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
"""The task is to parse a list of lines and use regular expressions to process
them differently according to what they contain.
If the line is all digits we want to convert that to an integer and divide it
by 2, if it is all non-digits then change it lower case otherwise represent it
with None.
For example, these lines:
288
ABCDEFGH
1A2B3C4D
Hello world
42
Will be converted to the list: [144, 'abcdefgh', None, None, 'hello world', 21]
The regular expression pattern for digits is \d and non-digits is \D.
Created on Sep 21, 2011
@author: paulross
"""
__author__ = 'Paul Ross'
__date__ = '2011-08-03'
__version__ = '0.1.0'
__rights__ = 'Copyright (c) 2011 Paul Ross. Copyright (c) 2015 AHL.'
import re
def matchLines(theLineS):
"""Given a list of lines return a list of objects:
If the line is all digits then divide it by 2.
If the line is all non-digits then make it lower case.
Other lines are represented by None."""
result = []
for l in theLineS:
# Your code goes here
pass
return result
def main():
text = """288
ABCDEFGH
1A2B3C4D
Hello world
42"""
result = matchLines(text.split('\n'))
print(result)
if __name__ == '__main__':
main()