82. Problem to get the list of prime numbers from a list.

In this Python list program, we will take a user input as a list and get the list of prime numbers in a given list with the help of the below-given steps.

List of prime numbers:

Steps to solve the program
  1. Take a list as input and create an empty list.
  2. Check whether the element from the given list is a prime number or not using for loop.
  3. If it is a prime number then add that element to the empty list.
  4. Print the list to see the output.
				
					#Input lists
list1 = [11, 8, 7, 19, 6, 29]
list2 = []

for value in list1:
    c=0
    for j in range(1,value):
        if value%j == 0:
            c += 1
    if c == 1:
        list2.append(value)

#Printing output
print(list2)
				
			

Output :

				
					[11, 7, 19, 29]
				
			

Related Articles

Count the total number of vowels in a list

List after removing n elements from both sides

Leave a Comment