Skip to content

Instantly share code, notes, and snippets.

@BlogBlocks
Last active July 18, 2018 03:33
Show Gist options
  • Select an option

  • Save BlogBlocks/15cc862c8a1953d67723cc6903a7532e to your computer and use it in GitHub Desktop.

Select an option

Save BlogBlocks/15cc862c8a1953d67723cc6903a7532e to your computer and use it in GitHub Desktop.
"""
This Hashes the list items and compares it to the a Hash of the proposed entry
if entry exists it prints. list and "is already in" and the entry so you may see.
if it enters it the new list is printed
import NoListDups
entrY = "XXiX"
x = ['XXX', 'yyy', 'zzz']
NoListDups.NoDupList(x, entrY)
print x
"""
import hashlib
def hashIt(mystring):
# Assumes the default UTF-8
hash_object = hashlib.md5(mystring.encode())
return(hash_object.hexdigest())
def NoDupList(lisT, entrY):
for item in lisT:
if hashIt(item) == hashIt(entrY):
print entrY," is already in ",lisT
break
else:
lisT.extend([entrY])
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment