Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import *
- import random
- from sets import Set
- class Animal(object):
- """docstring for """
- newid = count().next
- def __init__(self):
- self.id = Animal.newid()
- def print_memory_address(obj):
- for o in obj:
- print "id: %d | Memory address: %d" % (o.id, hash(o))
- ## Generate 10 Animal objects
- animals = [Animal() for i in range(10)]
- print_memory_address(animals)
- ## Shuffle and check the memory address
- random.shuffle(animals)
- print "Shuffled!"
- print_memory_address(animals)
- ## Check if generating a Set might change the address
- immutable = Set([animals[0]])
- print "Generated a Set!"
- print_memory_address(immutable)
- ## Check if the memory address might be changed after subtraction
- animals = list(Set(animals) - Set([animals[0]]))
- print "Removed once!"
- print_memory_address(animals)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement