Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,966 questions

51,908 answers

573 users

How to hash a set of GUIDs in Python

1 Answer

0 votes
import uuid

# A GUID (Globally Unique Identifier) and a UUID (Universally Unique Identifier)
# are essentially the same, both being 128-bit values used to uniquely identify
# information in computer systems.

def main():
    # Create a set containing three randomly generated UUIDs.
    # uuid.uuid4() produces a type‑4 GUID.
    guids = {
        uuid.uuid4(),
        uuid.uuid4(),
        uuid.uuid4()
    }

    # Compute a hash value for the entire set.
    # hash(...) is idiomatic Python for combining values into a single hash.
    hash_value = hash(frozenset(guids))   # sets must be frozen to be hashable

    # Print the GUIDs so we can see what was hashed.
    print("GUIDs in the set:")
    for g in guids:
        print(g)

    # Print the resulting hash value.
    print("\nHash of the GUID set:", hash_value)


if __name__ == "__main__":
    main()



"""
run:

GUIDs in the set:
381664de-edeb-45fa-bf66-6794dc2f00a7
fa895f77-1bc6-42ad-993a-9502feaf5109
ce55b239-95cb-480f-8f1b-f94879f80625

Hash of the GUID set: 5406426919634175225

"""

 



answered Jan 7 by avibootz
...