Skip to content

Instantly share code, notes, and snippets.

@copocaneta
Created December 9, 2024 22:25
Show Gist options
  • Save copocaneta/b9718dad9257385bfb9701af1554731e to your computer and use it in GitHub Desktop.
Save copocaneta/b9718dad9257385bfb9701af1554731e to your computer and use it in GitHub Desktop.
Improve this code by reducing verbosity
# Calculating squares of even numbers with an imperative loop
numbers = [1, 2, 3, 4, 5]
even_squares = []
for n in numbers:
if n % 2 == 0:
square = n * n
even_squares.append(square)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment