Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
HDL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RTSD
HDL
Commits
4401f8a6
Commit
4401f8a6
authored
6 years ago
by
Eric Kooistra
Browse files
Options
Downloads
Patches
Plain Diff
Added find_indices_where() and variants for ==, !=, <, <=, >, >=.
parent
603a594f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/oneclick/base/common.py
+21
-0
21 additions, 0 deletions
tools/oneclick/base/common.py
with
21 additions
and
0 deletions
tools/oneclick/base/common.py
+
21
−
0
View file @
4401f8a6
...
...
@@ -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)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment