cdactvm commited on
Commit
7cdea68
·
verified ·
1 Parent(s): 91052f5

Update processDoubles.py

Browse files
Files changed (1) hide show
  1. processDoubles.py +24 -31
processDoubles.py CHANGED
@@ -1,31 +1,24 @@
1
- #!/usr/bin/env python
2
- # coding: utf-8
3
-
4
- # In[ ]:
5
-
6
-
7
- import re
8
-
9
- def process_doubles(sentence):
10
- # Use regex to split 'डबल' followed by numbers/words without space (e.g., "डबलवन" -> "डबल वन")
11
- sentence = re.sub(r'(ਡਬਲ)(\S+)', r'\1 \2', sentence)
12
-
13
- tokens = sentence.split()
14
- result = []
15
- i = 0
16
-
17
- while i < len(tokens):
18
- if tokens[i] == "ਡਬਲ":
19
- if i + 1 < len(tokens):
20
- result.append(tokens[i + 1]) # Append the next word/number
21
- result.append(tokens[i + 1]) # Append the next word/number again to duplicate
22
- i += 2 # Skip over the next word since it's already processed
23
- else:
24
- result.append(tokens[i])
25
- i += 1
26
- else:
27
- result.append(tokens[i])
28
- i += 1
29
-
30
- return ' '.join(result)
31
-
 
1
+ import re
2
+
3
+ def process_doubles(sentence):
4
+ # Use regex to split 'डबल' followed by numbers/words without space (e.g., "डबलवन" -> "डबल वन")
5
+ sentence = re.sub(r'(ਡਬਲ)(\S+)', r'\1 \2', sentence)
6
+
7
+ tokens = sentence.split()
8
+ result = []
9
+ i = 0
10
+
11
+ while i < len(tokens):
12
+ if tokens[i] == "ਡਬਲ":
13
+ if i + 1 < len(tokens):
14
+ result.append(tokens[i + 1]) # Append the next word/number
15
+ result.append(tokens[i + 1]) # Append the next word/number again to duplicate
16
+ i += 2 # Skip over the next word since it's already processed
17
+ else:
18
+ result.append(tokens[i])
19
+ i += 1
20
+ else:
21
+ result.append(tokens[i])
22
+ i += 1
23
+
24
+ return ' '.join(result)