+def calculate_persistence(tokens_added, tokens_removed, exclude_ws = True, exclude_punct = False):
+ cond = True
+ ws_lex = ['break','whitespace']
+ punct_lex = ['period','qmark','epoint','comma','colon','scolon','paren_open','paren_close','brack_open','brack_close','dbrack_close','dbrack_open','tab_close','tab_open','dcurly_close','dcurly_open','equals','bar','etc','bold','italic','tag','comment_end','comment_start']
+
+
+ if exclude_ws:
+ cond = lambda t: cond and not t.type in ws_lex
+
+ if exclude_punct:
+ cond = lambda t: cond and not t.type in punct_lex
+
+ tokens_added = [t for t in tokens_added if cond(t)]
+ tokens_removed = [t for t in tokens_removed if cond(t)]
+