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
- Take a list as input and create an empty list.
- Check whether the element from the given list is a prime number or not using for loop.
- If it is a prime number then add that element to the empty list.
- 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
Python program to get a list with n elements removed from the left and right.
Python program to create a dictionary with two lists.
Python program to remove the duplicate item from the list using set.
Python program to insert a sublist into the list at a specific index.
Python program to calculate the bill per fruit purchased from a given fruits list.
Python program to calculate percentage from a given mark list, the max mark for each item is 100.