Skip to content

Instantly share code, notes, and snippets.

@chasefloyd
Created November 1, 2017 18:30
Show Gist options
  • Save chasefloyd/df2116dad1e4da4d616babc14c79b291 to your computer and use it in GitHub Desktop.
Save chasefloyd/df2116dad1e4da4d616babc14c79b291 to your computer and use it in GitHub Desktop.
Python solution for determining if a function is one to one
def isOneToOne(A, B, f):
x = []
i = 0
for i in range(len(f)):
x.append(f[i][1])
i+=1
x = sorted(x)
#print(x)
seen = set()
for i in x:
if i in seen:
return False
seen.add(i)
return True
A = [1, 2, 3]
B = [4, 5]
f = [[1, 4], [2, 5], [3, 4]]
print(isOneToOne(A, B, f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment