My Nexus 4 is now updated to Android lollipop 5.1 with build number LMY47D.
The L, I understand signifies Lollipop. but how does the rest come into picture
This is an interesting question, but no great mystery as a quick web search leads to the official word at https://source.android.com/source/build-numbers.html
The first letter is the code name of the release family, e.g. F is Froyo.
The second letter is a branch code that allows Google to identify the exact code branch that the build was made from, and R is by convention the primary release branch.
The next letter and two digits are a date code. The letter counts quarters, with A being Q1 2009. Therefore, F is Q2 2010. The two digits count days within the quarter, so F85 is June 24 2010.
Finally, the last letter identifies individual versions related to the same date code, sequentially starting with A; A is actually implicit and usually omitted for brevity.
Yes they are unique Identifier for each version Update.
detail info can be found here on developer.android.com
hope this clears out all the queries.