diff textshaper/split.py @ 51:c3b69728f291

finding indices now works
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 May 2015 08:33:23 -0700
parents 1284c99a94fa
children 8d8c1ac0e8e1
line wrap: on
line diff
--- a/textshaper/split.py	Sat May 16 21:02:07 2015 -0700
+++ b/textshaper/split.py	Sun May 17 08:33:23 2015 -0700
@@ -24,11 +24,16 @@
         except ValueError:
             return retval
 
-def findindices(_string, values):
+def indices(text, values):
     """
     returns ordered list of 2-tuples:
     (index, value)
     """
+    locations = {value: findall(text, value) for value in values}
+    indices = []
+    for key, values in locations.items():
+        indices.extend([(value, key) for value in values])
+    return sorted(indices, key=lambda x: x[0])
 
 def split_sentences(text, ends='.?!'):
     """split a text into sentences"""
@@ -58,7 +63,7 @@
     ends = '.?!'
 
     # find all ending punctuation
-    indices = {end: findall(text, end) for end in ends}
+
 
 
 if __name__ == '__main__':