Featured post

Blockchain Smart Contract Theory Behind

The smart contract in Blockchain is a kind of software application that works without human intervention based on the transaction logs and provide a solution to the user request. 
I want to share the back end mechanism in the Smart Contract of Blockchain.

Smart Contract Mechanism What is Smart ContractA smart contract is a protocol which can auto-execute, facilitate, verify, or enforce the negotiation of a contract.Agreement between two parties you can say as a contract.Incorporating the rules of the physical contract into the computing world, you can say as a smart contractBlockchain supports you to create smart contracts.Smart Contracts are self-executing programs which run on the blockchain and are capable of enforcing rulesUsing Blockchain as a platform and making an agreement or contract between more than two parties, you can say as Smart Contract.Traditional Markets  4 Top Benefits of Smart ContractCurrently, smart contracts are being used only in Crypto CurrenciesNow Smart Contra…

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

Blue Prism complete tutorials download now

2 Top Software Developer Resume Templates