Skip to content

Instantly share code, notes, and snippets.

@diogovk
Created July 25, 2014 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diogovk/9d46c46a2ec171903dde to your computer and use it in GitHub Desktop.
Save diogovk/9d46c46a2ec171903dde to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
def idempotent(other):
myset={1,2,3}
return myset.union(other)
def non_idempotent(other):
mylist=[1,2,3]
mylist.extend(other)
return mylist
x=idempotent({100,200})
y=non_idempotent([100,200])
for i in range(1,5):
print(str(i)+": idempotent: "+str(x)+" || non_idempotent: "+str(y))
x=idempotent(x)
y=non_idempotent(y)
# 1: idempotent: {200, 1, 2, 3, 100} || non_idempotent: [1, 2, 3, 100, 200]
# 2: idempotent: {1, 2, 3, 100, 200} || non_idempotent: [1, 2, 3, 1, 2, 3, 100, 200]
# 3: idempotent: {1, 2, 3, 100, 200} || non_idempotent: [1, 2, 3, 1, 2, 3, 1, 2, 3, 100, 200]
# 4: idempotent: {1, 2, 3, 100, 200} || non_idempotent: [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 100, 200]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment