Skip to content

Commit 78683c1

Browse files
author
Peter Combs
committed
Add startswith and contains lambdas to Utils.py
1 parent 3fe86e9 commit 78683c1

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,21 @@ def to_number(dataval):
3131

3232
except ValueError:
3333
return dataval
34+
35+
36+
def contains(string_or_iterable):
37+
if isinstance(string_or_iterable, str):
38+
return lambda x: string_or_iterable in x
39+
else:
40+
return lambda x: any(i in x for i in string_or_iterable)
41+
42+
def startswith(string_or_iterable):
43+
if not isinstance(string_or_iterable, str):
44+
string_or_iterable = tuple(string_or_iterable)
45+
return lambda x: x.startswith(string_or_iterable)
46+
47+
def sel_contains(string_or_iterable):
48+
return dict(crit=contains(string_or_iterable), axis=1)
49+
50+
def sel_startswith(string_or_iterable):
51+
return dict(crit=startswith(string_or_iterable), axis=1)

0 commit comments

Comments
 (0)