Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update limit.py #502

Merged
merged 2 commits into from
May 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions algorithms/arrays/limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@

# tl:dr -- array slicing by value
def limit(arr, min_lim=None, max_lim=None):
result = []
if min_lim is None and max_lim:
for i in arr:
if i <= max_lim:
result.append(i)
elif max_lim is None and min_lim:
for i in arr:
if i >= min_lim:
result.append(i)
elif max_lim and min_lim:
for i in arr:
if i >= min_lim and i <= max_lim:
result.append(i)
else:
result = arr
return result
if min_lim is None and max_lim is not None:
return [x for x in arr if x <= max_lim]
if max_lim is None and min_lim is not None:
return [x for x in arr if x >= min_lim]
if max_lim is not None and min_lim is not None:
return [x for x in arr if min_lim <= x <= max_lim]
return arr