Skip to content

Instantly share code, notes, and snippets.

@sumaiyaasif
Created April 16, 2018 18:29
Show Gist options
  • Save sumaiyaasif/65b13975fd72b035ebc179918dc4f620 to your computer and use it in GitHub Desktop.
Save sumaiyaasif/65b13975fd72b035ebc179918dc4f620 to your computer and use it in GitHub Desktop.
Answer to cassidoo interview question for 4.9.2018
# 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