0

I am trying to generate a list of pairs using a comprehension, that creates the pairs two at a time. I can create a list of lists, where each sub-list is two pairs, e.g.,:

mylist = [[(f'2i_{i}',2*i),(f'8i_{i}',8*i)] for i in range(1,4)]

# [[('2i_1', 2), ('8i_1', 8)], [('2i_2', 4), ('8i_2', 16)], [('2i_3', 6), ('8i_3', 24)]]

or a list of pairs of pairs, e.g.,:

mylist = [((f'2i_{i}',2*i),(f'8i_{i}',8*i)) for i in range(1,4)]

# [(('2i_1', 2), ('8i_1', 8)), (('2i_2', 4), ('8i_2', 16)), (('2i_3', 6), ('8i_3', 24))]

but what I want it to look like is:

# [('2i_1', 2), ('8i_1', 8), ('2i_2', 4), ('8i_2', 16), ('2i_3', 6), ('8i_3', 24)]

Is there a simple way of using a comprehension to create a list like this?

guskenny83
  • 1,321
  • 14
  • 27

0 Answers0