Victor Ng writes about Python's tuple syntax for length one tuples.
Not that I use a lot of explicit length one tuples, but here's something you can do instead. Redefine the tuple
function to accept non-sequences. If so, just put them in a length one tuple.
Then you can express an explicit length one tuple as
def tuple(x):
try:
return original.tuple(x)
except TypeError:
return original.tuple([x])
tuple(x)
No comments:
Post a Comment