Python: Return unique strings from a list of strings
30. Remove Duplicates from a List of Strings Using a Set
Write a Python program to remove all duplicates from a given list of strings and return a list of unique strings. Use the Python set data type.
Sample Solution:
Python Code:
Sample Output:
Original list of strings: ['foo', 'bar', 'abc', 'foo', 'qux', 'bar', 'baz'] strs of strings after removing duplicates: ['abc', 'qux', 'foo', 'baz', 'bar'] Original list of strings: ['Python', 'Exercises', 'Practice', 'Solution', 'Exercises'] List of strings after removing duplicates: ['Solution', 'Python', 'Exercises', 'Practice']
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to remove duplicate strings from a list using a set and then convert the set back to a list.
- Write a Python program to iterate over a list and add each unique string to a new list using a set for tracking.
- Write a Python program to implement a function that returns a list of unique strings from a given list while preserving the original order.
- Write a Python program to use list comprehension in combination with a set to filter out duplicate strings from a list.
Go to:
Previous: Third largest number from a list of numbers using set.
Next: Python Collections Exercise Home.
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.