Featured post

Best Machine Learning Book for Beginners

You need a mixof different technologies for Data Science projects. Instead of learning many skills, just learn a few. The four main steps of any project are extracting the data, model development, artificial intelligence, and presentation. Attending interviews with many skills is not so easy. So keep the skills short.
A person with many skills can't perform all the work. You had better learn a few skills like Python, MATLAB, Tableau, and RDBMS. So that you can get a job quickly in the data-science project.
Out of Data Science skills, Machine learning is a new concept. Why because you can learn Python, like any other language. Tableau also the same. Here is the area that needs your 60% effort is Machine learning.  Machine Learning best book to start.

Related Posts How to write multiple IF-conditions in Python Simplified

Python LIst Remove Duplicates Dictionary Vs Append

In this post, I am sharing top ideas to remove duplicates from Python list.



Python: How to Remove Duplicates From List

💥Idea 1:  Remove Duplicates Using Append.

# Given a list with duplicates

list_with_duplicates = [1,2,3,12,1,2,3,4,5,6,1,2,3,7,8,9]

The first approach might be a simple brute force approach:

list_without_duplicates = []

for pd in list_with_duplicates:
  if pd not in list_without_duplicates:
   list_without_duplicates.append(pd)
print(list_without_duplicates)

Result:

[1, 2, 3, 12, 4, 5, 6, 7, 8, 9]

This method might works. But, it has some performance issues for large lists since you are essentially creating a full copy of the list. 

Real-time.

Idea 1:  Remove Duplicates Using Append.



💥Idea 2: Remove Duplicates Using Dictionary.


# Convert the list to a dictionary

dict_without_duplicates = dict(zip(list_with_duplicates, list_with_duplicates))

print(dictionary_without_duplicates)

Result.

{1: 1, 2: 2, 3: 3, 12: 12, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9}


Real-time.

Idea 2: Remove Duplicates Using Dictionary.


Once again, this works and has the advantage of taking less space than duplicating the entire list. 

*Notes: Of course, we still need to convert it back to a list when we are done, which might be somewhat painful since we must extract the keys and add them to a list.

Comments

Popular posts from this blog

Hyperledger Fabric: 20 Real Interview Questions

How to Fix Python Syntax Errors Quickly

Python Assigning Multiple Values at Once