Last active
June 24, 2019 17:16
-
-
Save crodriguez1a/e7c20012ecf32f92f5fa5617997d1d0c to your computer and use it in GitHub Desktop.
Python Learning Series: Remove Even Challenge
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
num = [1,2,3,4,5,6,7] | |
# explore modulo | |
for i in num: | |
print(i, i % 2 != 0) | |
# long form | |
def remove_even(List): | |
odds = [] | |
for i in List: | |
if i % 2 != 0: | |
odds.append(i) | |
return odds | |
y = remove_even(num) | |
print(y) | |
# short form | |
def remove_even_lc(List): | |
return [i for i in List if i % 2 != 0] # list comphrension | |
z = remove_even_lc(num) | |
print(z) | |
# other comprehension types | |
print({ i for i in {1,2,3} }) | |
# https://python-reference.readthedocs.io/en/latest/docs/comprehensions/set_comprehension.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment