-1

I want to print Alternate A.P and G.P series like:

- 2 2 4 6 6 18 8 54 10 162 12 486... i.e (A1 G1 A2 G2 A3 G3 .....)

here variable is with literal meaning asinged below. I found in form of

[(2, 2), (4, 6), (6, 18), (8, 54), (10, 162), (12, 486), (14, 1458), 
 (16, 4374), (18, 13122), (20, 39366)]

How can I find as expected?

a,d,r,length=2,2,3,10
lst=[( a+(n-1)*d, a*r**(n-1) ) for n in range(1,length+12)]
print(lst)
Patrick Artner
  • 50,409
  • 9
  • 43
  • 69

1 Answers1

0

if you just want to flatten your list, you could use itertools.chain.from_iterable:

from itertools import chain

chn = chain.from_iterable(lst)
flat_tuple = tuple(chn)
print(flat_tuple)  # (2, 2, 4, 6, 6, 18, 8, 54, 10, 162, ...)

or if you need that as a string you could to this:

from itertools import chain

strg = ' '.join(str(i) for i in chain.from_iterable(lst))
print(strg)  # 2 2 4 6 6 18 8 54 10 162 12 486 14 ...
hiro protagonist
  • 44,693
  • 14
  • 86
  • 111