Created
April 16, 2018 18:29
-
-
Save sumaiyaasif/65b13975fd72b035ebc179918dc4f620 to your computer and use it in GitHub Desktop.
Answer to cassidoo interview question for 4.9.2018
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given an unsorted array arr and a number n, | |
# delete all numbers in arr that are greater than n. | |
arr = [3,4,6,1,8,2,6,7,10] | |
num = 7 | |
def deleteElements(arr, num): | |
for x in arr: | |
if x > num: | |
arr.remove(x) | |
return arr | |
print deleteElements(arr, num) | |
# Alternative way that generates a new list without altering original | |
newArr = list(filter(lambda x : x <= num, arr)) | |
print newArr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment