0

Is it possible two have to separate for loop in a single comprehension? Something like

A = [i * 2 in range(5, 10), j + 2 for j in range(5) ]
# To get A = [10, 12, 14, 16, 19, 2, 3, 4, 5, 6]

The closest that comes to what I need is

A = [*[i * 2 for i in range(5, 10)], *[j + 2 for j in range(5)]]

Is there a better (more python-ic) way of doing this?

Nikhil H
  • 103
  • 1
  • 7

1 Answers1

3

You can just add both lists:

A = [i * 2 for i in range(5, 10)] + [j + 2 for j in range(5) ]
Tarifazo
  • 4,118
  • 1
  • 9
  • 22