Skip to content

Instantly share code, notes, and snippets.

@brainyfarm
Last active August 8, 2016 10:44
Show Gist options
  • Save brainyfarm/1894b830be6f389840bc6a57aafa9582 to your computer and use it in GitHub Desktop.
Save brainyfarm/1894b830be6f389840bc6a57aafa9582 to your computer and use it in GitHub Desktop.
FreeCodeCamp: Falsy Bouncer (Python)
"""
null in js, None in python
false is False
Remove all falsy values from an array.
Falsy values in JavaScript are false, null, 0, "", undefined, and NaN
I had to modify some stuff from this challenge due to some differences
in Javascript and Python
"""
def bouncer(the_list):
truthful_list = []
for element in the_list:
if element is not False and element is not "" and element is not None and element is not 0:
truthful_list.append(element)
return truthful_list
print bouncer([7, "ate", "", False, None, 9, 0])
"""
null in js, None in python
false is False
Remove all falsy values from an array.
Falsy values in JavaScript are false, null, 0, "", undefined, and NaN
I had to modify a lot of stuff from this very challenge due to some differences
in JS and Python
"""
def bouncer(the_list):
# List comprehension rocks!
return [element for element in the_list if element is not False and element is not "" and element is not None and element is not 0]
print bouncer([7, "ate", "", False, None, 9, 0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment