Prove that $f: X \rightarrow Y$ is one-to-one, if and only if : $g: P(Y)\rightarrow P(X)$ , $g(Y)= \{ x\in X : f(x)\in Y \} $ is onto My attempt (for first direction), I said that suppose that $f$ is one-to-one and $g$ is not onto, 
then there exists $X'\subset X$, such that for all $Y'\subset Y$ : $g(Y')\ne X$ 
then if $f$ is one to one : $\forall x\in X, \exists! y\in Y : f(x)=y $ 
hence there must be a subset $Y'\subset Y$ that satisfies $g(Y')=X'$ 
which contradicts that $g$ is not onto.
but I really think I have made some mistakes since looking at it again I could have proved it in the same way without $f$ being one to one.
Any help or corrections or answers are appreciated.
Thanks in advance!

The fact that $f$ is one-to-one does not mean that for each $x\in X$ there is a unique $y\in Y$ such that $f(x)=y$: that’s true simply because $f$ is a function. The fact that $f$ is one-to-one means that for each $y\in Y$ there is at most one $x\in X$ such that $f(x)=y$.
You’re right that your argument doesn’t work: it would apply even if $f$ were a constant function, and in that case it’s clear that $g$ is not onto.
Suppose that $f$ is one-to-one, and let $A\subseteq X$; we want to find an $S\in\wp(Y)$ such that $g(S)=A$. The natural candidate is $f[A]$, i.e., $\{f(x):x\in A\}$, so let $S=f[A]$. Certainly $g(S)=f^{-1}\big[f[A]\big]\supseteq A$, so we need only show that $g(S)\subseteq A$. Let $x\in g(S)$; then $f(x)\in S$. Let $y=f(x)$; $y\in S$, so there is an $a\in A$ such that $f(a)=y$. But then $f(x)=f(a)$, and $f$ is one-to-one, so $x=a\in A$. This shows that $g(S)\subseteq A$ and hence that $g(S)=A$, as desired, so $g$ is onto.
Now suppose that $f$ is not one-to-one. Then there are distinct $x_0,x_1\in X$ such that $f(x_0)=f(x_1)=y$, say. Let $A=\{x_0\}$, and suppose let $S\in\wp(Y)$ be such that $x_0\in g(S)$. By definition this means that $f(x_0)\in S$, so $y\in S$. But $f(x_1)=y$, too, so $x_1\in g(S)$ as well. Thus, $g(S)\supseteq\{x_0,x_1\}\supsetneqq A$, and we see that there is no $S\in\wp(Y)$ such that $g(S)=A$. That is, $g$ is not onto. This shows that if $g$ is onto, $f$ must be one-to-one and completes the proof.
