Created
November 1, 2017 18:30
-
-
Save chasefloyd/df2116dad1e4da4d616babc14c79b291 to your computer and use it in GitHub Desktop.
Python solution for determining if a function is one to one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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