76. Problem to remove the duplicate string from the list.

In this Python list program, we will take a user input as a list and remove the duplicate string from the list with the help of the below-given steps.

Remove the duplicate string from list:

Steps to solve the program
  1. Take a list containing strings as input.
  2. Add the strings from the given list to another list using for loop. 
  3. If a string repeats then do not add it.
  4. Print the list to see the output.
				
					#Input lists
list1 = ["python", "is", "a", "best", "language", "python", "best"]
list2 = []

for words in list1:
    if words not in list2:
        list2.append(words)

#Printing output
print(list2)
				
			

Output :

				
					['python', 'is', 'a', 'best', 'language']
				
			

Related Articles

Insert an element before each element of a list

Calculate the factorial of each item in the list

Leave a Comment