Python filter list using hash table

Python filter list using a hash table


#Python filter list using hash table

items = ["Banana", "Apple", "Avocado", "Grapes", "Oranges", "Banana", "Apple", "Avocado", "Kiwi", "Pear"]

#Hash table to perform filter
filter = dict()

#Loop over each hash table and add to the hash table
for key in items:
    filter[key] = 0
#Create a set from the resulting hash table
result = set(filter.keys())
print(result)

#This filter takes time to go through each loop depending on the size of the list items to filter



-------------------------------------------------------------------------------------------------------------------------
#Output
{'Apple', 'Oranges', 'Banana', 'Grapes', 'Kiwi', 'Avocado', 'Pear'}

Comments

Popular posts from this blog

How to write to a file in Kotlin

Python Tkinter example