Using a Lambda Expression to Determine if a Number is Odd or Even

There's a simple way to use a lambda expression to determine if a number is either odd or even. Here's an example of how you can do this while iterating over a list of integers:

 

clip_image001

 

The key algorithm is n % 2 == 1. Simple is as simple does.

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.