Skip to content

Commit

Permalink
Merge pull request #41 from akhanf/filterlist_set
Browse files Browse the repository at this point in the history
changed set to list to preserve ordering
  • Loading branch information
akhanf authored Apr 15, 2021
2 parents a65743f + aa5a9ec commit a384073
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions snakebids/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,19 +338,19 @@ def filter_list(zip_list, wildcards, return_indices_only=False):
... }
True
"""
keep_indices = set()
keep_indices = list()
for key, val in wildcards.items():
# get indices where wildcard exists
if key not in zip_list.keys():
continue
indices = {i for i, v in enumerate(zip_list[key]) if v == val}
indices = [i for i, v in enumerate(zip_list[key]) if v == val]
if len(keep_indices) == 0:
keep_indices = indices
else:
keep_indices = keep_indices.intersection(indices)
keep_indices = [x for x in indices if x in keep_indices]
# Now we have the indices, so filter the lists
if return_indices_only:
return list(keep_indices)
return keep_indices
return {
key: [zip_list[key][i] for i in keep_indices]
for key, val in zip_list.items()
Expand Down

0 comments on commit a384073

Please sign in to comment.