Consider the following code mapping:
$$a \mapsto 010, \quad b\mapsto 001, \quad c\mapsto 01$$
It's easy to see that the code isn't lossless by observing the code $01001$, which can be translated to "ac" or "cb".
Given a general code, how can you tell if it's lossless or not? I don't think trial and error is the best approach (though for small examples like the one I presented it's enough).
The property you are looking for is called unique decodability, usually abbreviated to UD. There is a fairly simple algorithm which decides whether a code is UD. The idea is essentially to perform a breadth-first search for two strings which code the same way; in your example
acandcb.Let $S = \def\w#1{\mathtt{#1}}\{\w{010}, \w{001}, \w{01}\}$, as in your example. These words are called code words. We want to find two sequences of code words whose concatenations are the same.
There is a simple theorem that says that this is impossible unless one code word is a prefix of another. (Otherwise, any concatenation of code words begins with exactly one of the code words, and this must be the first word from which it was composed.) So start by finding two words, one of which is a prefix of another; if there is none, the code is UD. In your example we find
01and010. Then we write $$\w{01}x = \w{010}y$$ and try to solve for $x$ and $y$. It is clear that $x$ must begin with0, so we have either $x=\w{01}x'$ or $x = \w{001}x'$:$$\begin{array}{lrl} \w{01}\,&\w{01}\,x' & = \w{010}\,y\\ \w{01}\,&\w{001}\,x' & = \w{010}\,y \end{array}$$
We may in general have to examine both of these possibilities. Examining the first of these, we see $\w{0101}x' = \w{010}y$, so $y$ must begin with
1, which is impossible, since no code word begins with1, so we discard this equation. Examining the second equation instead, we see $\w{01}\ \w{001} x' = \w{010} y$, so $y$ must begin with01. It must therefore be either010or01. We recognize immediately that $y=\w{01}$ and $x'=\w{}$ solves the equation, and stop, having discovered that01 001=010 01.The formal statement of the algorithm has a queue of unexamined equations, each of the type $pv_1 = psv_2$ as above, where $p$ is a common prefix. This equation is represented in the algorithm with the single string $s$. For example, the equation we had above with $\w{01}\,\w{001}\,x'=\w{010}\,y$ has $p=\w{010}$ and $s=\w{01}$ and is represented in the algorithm as the string $\w{01}$.
The complete description is:
There is no requirement to use a queue; the items could be taken from it in FIFO order, or any other order, and the algorithm will still function. I am not aware of any performance guarantees that result from using a queue.
It's not hard to annotate each queue item with the two code word sequences that reached it, so that when the algorithm terminates with a non-UD code, it has constructed an example of two sequences of code words with identical concatenations. Here is some Perl code I wrote that does this.