A container having 2 or more elements could be called a "plural container". A container with no elements could be called an "empty container".
But what is the terminology for a container whose current size is exactly 1 element?
I would use the term "unary" but that refers to operators that take exactly 1 argument.
The reason I would like a term for this is that I am writing a boolean method to check if two data structures are both of size exactly one and I want a good name for the method. Currently I have:
def length_is_1(self, x, y):
return len(x) == 1 and len(y) == 1
Best Answer
Do not come up with a new word. Your name is perfectly fine: It is unambiguous and specific and consequently leaves no doubt to the reader what you are talking about.
By contrast, singleton, unary, 1-tuple or any other term borrowed from mathematics or software engineering carries with it a baggage of preconceptions which are confusing. A list with a single element in it is emphatically not a singleton. It has nothing to do with unary operators, and a list is clearly not a tuple in C++. It is a list with one element in it, not more, not less.
That is sometimes a perceived downside of a simple approach in programming: It seems unsophisticated, and hence of a lesser value. Look at Duff's device! Marvel at the ingenuity of boost.lambda! But then listen to Jim Radigan, who leads the VC++ compiler team:
That your peer is able to understand your code right away because it is plain and simple and calls things what they are is not a sign that you didn't realize your full programming potential. It is a sign of excellence. Do not look for a Latin word.