1.

Write a list comprehension to produce the list: [1, 2, 4, 8, 16……212].(a) [(2**x) for x in range(0, 13)](b) [(x**2) for x in range(1, 13)](c) [(2**x) for x in range(1, 13)](d) [(x**2) for x in range(0, 13)]The question was posed to me in my homework.My query is from List Comprehension topic in section Lists & List Comprehension of Python

Answer»

Right ANSWER is (a) [(2**x) for x in range(0, 13)]

To explain: The REQUIRED list comprehension will print the numbers from 1 to 12, each raised to 2. The required answer is THUS, [(2**x) for x in range(0, 13)].



Discussion

No Comment Found

Related InterviewSolutions