Skip to content

Instantly share code, notes, and snippets.

@jgarciabu
Created July 27, 2017 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgarciabu/192b4ca589edfb8dc9590c35975762a2 to your computer and use it in GitHub Desktop.
Save jgarciabu/192b4ca589edfb8dc9590c35975762a2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 27 15:05:44 2017
@author: Jeff Garcia
Let’s say I give you a list saved in a variable:
a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]. Write one line of Python that
takes this list a and makes a new list that has only the even elements of
this list in it.
"""
a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
print([x for x in a if x % 2 == 0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment