Find Non-Duplicate Elements from List in Python


In Python, you can achive find non-duplicate elements from List as following:

1. For Integer List

nums = [1, 4, 8, 1, 11, 5, 4]
non_duplicate_list = [num for num in nums if nums.count(num) == 1]
print(non_duplicate_list)

This code will produce the output:

[8, 11, 5]

2. For String List

cities = ["Bengaluru", "Varanasi", "New Delhi", "Bengaluru"]
non_duplicate_list = [city for city in cities if cities.count(city) == 1]
print(non_duplicate_list)

This code will produce the output:

['Varanasi', 'New Delhi']

References

  1. Java 8 – Find Non Duplicate Elements from List

Similar Posts

About the Author

Atul Rai
I love sharing my experiments and ideas with everyone by writing articles on the latest technological trends. Read all published posts by Atul Rai.