Ok. Um - yes. That is *way* more elegant than my code.
However, my code has no dependencies - which is important to me, at least, because (for reasons I'd rather not go into because they're bad for my blood-pressure) I can't use modules at work, which is where I use the code.