Skip to content
Snippets Groups Projects
Commit 4401f8a6 authored by Eric Kooistra's avatar Eric Kooistra
Browse files

Added find_indices_where() and variants for ==, !=, <, <=, >, >=.

parent 603a594f
Branches
No related tags found
No related merge requests found
......@@ -421,6 +421,27 @@ def index_a_in_multi_b(a, b):
pass
return None
def find_indices_where(in_list, value, condition=operator.eq):
"""Return list of indices in in_list that match the condition value
Condition operators from import operator are e.g.
operator.eq : ==
operator.ne : !=
operator.lt : <
operator.le : <=
operator.gt : >
operator.ge : >=
"""
return [i for i,x in enumerate(in_list) if condition(x, value)]
def find_indices_where_eq(in_list, value): return find_indices_where_value(in_list, value, operator.eq)
def find_indices_where_ne(in_list, value): return find_indices_where_value(in_list, value, operator.ne)
def find_indices_where_lt(in_list, value): return find_indices_where_value(in_list, value, operator.lt)
def find_indices_where_le(in_list, value): return find_indices_where_value(in_list, value, operator.le)
def find_indices_where_gt(in_list, value): return find_indices_where_value(in_list, value, operator.gt)
def find_indices_where_ge(in_list, value): return find_indices_where_value(in_list, value, operator.ge)
def unique(in_list):
"""
Extract unique list elements (without changing the order like set() does)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment