Python Practice › List Programs › Program 77
Factorial of each item
Write a Python program to get the factorial of each item in a list.
Input
[3, 4, 5, 6]
Output
[6, 24, 120, 720]
Approach
math.factorialon each item.
Solution
import mathprint([math.factorial(n) for n in [3, 4, 5, 6]])Output
[6, 24, 120, 720]
Learn the concept
New to this topic? Read the lesson, then come back.