Last active
August 8, 2016 10:44
-
-
Save brainyfarm/1894b830be6f389840bc6a57aafa9582 to your computer and use it in GitHub Desktop.
FreeCodeCamp: Falsy Bouncer (Python)
This file contains hidden or 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
""" | |
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]) |
This file contains hidden or 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
""" | |
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