Rewrite the following Python code by introducing list comprehensions.

Input: even_numbers = []
for i in range(1,21):
if i % 2 == 0:
even_numbers.append(i)

Output: even_numbers = [i for i in range(1, 21) if i % 2 == 0]

Prompt: Below is an instruction that describes a task. Write a response that appropriately completes the request.

### Instruction:
Rewrite the following Python code by introducing list comprehensions.

### Input:
even_numbers = []
for i in range(1,21):
if i % 2 == 0:
even_numbers.append(i)

### Output:
even_numbers = [i for i in range(1, 21) if i % 2 == 0]

editor
We will be happy to hear your thoughts

Leave a reply

vesaire.com
Logo
Compare items
  • Total (0)
Compare
0
Shopping cart