Show that a function is continuous if and only if for every $B ∈ S_Y$ , the set $f^{−1}(B)$ is open in $X$. 
Let $f : X → Y$ be a map between two topological spaces $X$ and $Y$ , and $S_Y ⊆ 2^Y$ a sub-basis for the topology of $Y$ . Show that $f$ is continuous if and only if for every $B ∈ S_Y$ , the set $f^{−1}(B)$ is open in $X$.

My attempt:
Definition: a function $f: X→Y$ is continuous if for every open $U \in Y$, we have $f^{-1}(U)$ is open in $X$.

*

*$=>$: If $B \in S_Y$, then $B$ is open in $Y$. Because $f$ is continuous, $f^{-1}(B)$ is open, by definition of continuity.


*$<=$: Let $V⊆Y$ be an open subset, and since $S_Y$ is a sub-basis, then $Y = U_{B \in S}B$, so $V ⊆ U_{B \in S}B$, so we can write $V$ as $V = U(\cap_{B \in S}B)$. Hence, $f^{-1}(V)= f^{-1}(U(\cap_{B \in S}B)) = Uf^{-1}(\cap_{B \in S}B)$, and since $B$ is open, then so as $\cap_{B \in S} B$, thus $Uf^{-1}(\cap_{B \in S}B)$ is open, which implies that $f^{-1}(V)$ is open, hence $f$ is continuous.
Is my attempt correct? Any help please?
 A: A straightforward proof of $(\Leftarrow)$ is the following. Let $V$ be any open subset of $Y$ and $y\in Y$ be ainy point. There exists a finite subfamily $\mathcal B_y$ of $S_Y$ such that $y\in\bigcap \mathcal B_y\subset V$. Then
$f^{-1}(y)\subset f^{-1}\left(\bigcap \mathcal  B_y\right)\subset f^{-1}(V)$. Thus a set
$$f^{-1}(V)=\bigcup_{y\in Y} f^{-1}\left(\bigcap \mathcal B_y\right)= \bigcup_{y\in Y} \bigcap_{U\in \mathcal  B_y}  f^{-1}(U)$$ is open.
A: If $S_Y$ is a sub-basis of a topology $\tau$ in the space $Y$, then
$$
\mathcal B=\{V_1\cap\cdots\cap V_n: n\in\mathbb N, \,V_1,\ldots,V_n\in S_Y\}
$$
is a basis of the topology of $Y$ and the topology is equal to
$$
\tau=\big\{\cup T: T\subset \mathcal B\big\}.
$$
If $f^{-1}(V)$ is open for all $V\in S_Y$, and $W=V_1\cap\cdots\cap V_n\in\mathcal B$, then
$$
f^{-1}(W)=f^{-1}(V_1\cap\cdots\cap V_n)=f^{-1}(V_1)\cap\cdots\cap f^{-1}(V_n)
$$
and hence $f^{-1}(W)$ is open, for all $W\in \mathcal B$, as a finite intersection of open sets. Finally, if $V\in \tau$,
then there exist a set of indices $I$ and $V_i\in \mathcal B$, $i\in I$, such
$V=\bigcup_{i\in I}V_i$, and thus
$$
f^{-1}(V)=\bigcup_{i\in I}f^{-1}(V_i)
$$
and hence $f^{-1}(V)$ is also open as an arbitrary union of open sets.
