Getting only element from a single-element list in Python?
Raises exception if not exactly one item: Sequence unpacking: singleitem, = mylist # Identical in behavior (byte code produced is the same), # but arguably more readable since a lone trailing comma could be missed: [singleitem] = mylist Rampant insanity, unpack the input to the identity lambda function: # The only even semi-reasonable way to … Read more