Skip to content

Instantly share code, notes, and snippets.

@shihongzhi
Created June 30, 2010 07:19
Show Gist options
  • Save shihongzhi/458354 to your computer and use it in GitHub Desktop.
Save shihongzhi/458354 to your computer and use it in GitHub Desktop.
def odd(n):
return n%2
li=[1,2,3,5,9,10,256,-3]
filter(odd,li) //输出[1,3,5,9,-3]
@cslarsen
Copy link

Another way is just checking to see if the LSB is set:

def odd(n):
        return n & 1

That is a much quicker operation than modulus, but not sure if it's faster in a language like python. Cheers!

@shihongzhi
Copy link
Author

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment