Skip to content

Instantly share code, notes, and snippets.

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