by Estragon · 14y ago · 0 comments
varname, = [x for x in l if predicate_with_single_truth_value(x)]
The comma after varname is an implicit assert that the list comprehension only contains one element.This sort of code would be very confusing when I'm just quickly reading through a procedure trying to find the potential bug.
(varname,) = [x for x in l if predicate_with_single_truth_value(x)] [varname] = [x for x in l if predicate_with_single_truth_value(x)]varname ,= [...]
Superficially it looks like an operator, but I suspect that's merely because of whitespace freedom; i.e., a, = [0] is equivalent to a,=[0] and a ,= [0].
http://stackoverflow.com/questions/1642028/what-is-the-name-...
Sure it is! And in Python 3 there's the ,_*= operator, similar to lisp's car:
varname ,_*= [1, 2, 3] # varname == 1Even Python removed one of its most prominent cases of this, the print command. In Python 2.x you could have a trailing comma after a print to omit the new-line but Python 3's print() function requires print('something', end=' ') to be more explicit about it.