5

If c = collections.Counter then the docs show an expression +c that has the effect "remove zero and negative counts." I haven't seen any such expression before in python. Why does the expression have that effect? What does it expand to?

ETA: Digging into the class I see that there is also a -c or Counter.__neg__ operator that "Subtracts from an empty counter. Strips positive and zero counts, and flips the sign on negative counts."

These operator methods seem convenient but not intuitive. Are there any precedents for using the unary operator in this way?

feetwet
  • 3,248
  • 7
  • 46
  • 84

0 Answers0