77. Problem to calculate the factorial of each item in the list.

In this Python list program, we will calculate the factorial of each item in the list with the help of the below-given steps.

Factorial of each item in list:

Steps to solve the program
  1. Take a list as input.
  2. Create a function for calculate factorial of a number.
  3. Create a new list and calculate the factorial of each number from the given list using list comprehension.
  4. Print the new list to see the output.
				
					#Creating function
def factorial(n):
    fact = 1
    
    for i in range(1, n + 1):
        fact *= i
    return fact

#Input list
list1 = [1, 2, 3, 4]
list1_factorials = [factorial(value) for value in list1]

#Printing output
list1_factorials
				
			

Output :

				
					[1, 2, 6, 24]
				
			

Related Articles

Remove the duplicate string from the list

Get a list of Fibonacci numbers from 1 to 20

Leave a Comment