title: What is the difference between these two solutions - lambda or loop - Python
body: <p>I want to calculate the sum of even numbers within a domain. I have two solutions, but I'm not sure of the advantages/disadvantages of each. Which is the optimal solution?</p>
  
  <pre><code>import sys
  domain = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  Cal1 = sum(filter(lambda n : n % 2 == 0, domain))
  Cal2 = sum([n for n in domain if n % 2 == 0])
  sys.stdout.write("Cal1 = {0}\n".format(Cal1))
  sys.stdout.write("Cal2 = {0}\n".format(Cal2))
  </code></pre>