▲ 2 r/learnpython
Hello, everyone, I would like to know how you can do this in python more dynamically. I was able to do it but i had to copy and paste the powers repeatedly to get the result needed. I would assume you would need 2 loops in the list comprehension but i dont know how to.
"""
Using list comprehension create the following list of tuples:
[(0, 1, 0, 0, 0, 0, 0),
(1, 1, 1, 1, 1, 1, 1),
(2, 1, 2, 4, 8, 16, 32),
(3, 1, 3, 9, 27, 81, 243),
(4, 1, 4, 16, 64, 256, 1024),
(5, 1, 5, 25, 125, 625, 3125),
(6, 1, 6, 36, 216, 1296, 7776),
(7, 1, 7, 49, 343, 2401, 16807),
(8, 1, 8, 64, 512, 4096, 32768),
(9, 1, 9, 81, 729, 6561, 59049),
(10, 1, 10, 100, 1000, 10000, 100000)]
"""
lst = [(x, 1, x, x**2, x**3,x**4,x**5 )for x in range(0,11)]
print(lst)
u/Fun-Pitch-6938 — 4 days ago