Typo in collections.Counter class example
Hello, It seems that I found micro bug in Python documentation describing collections.Counter class<http://docs.python.org/3.3/library/collections.html#counter-objects> . There is the following snippet of code c.most_common()[:-n:-1] # n least common elements Actually this expression returns not *n* least common elements, but rather *n - 1,* beacuse second boundary is not included (as usual with slices). You probably meant c.most_common()[-n:] or c.most_common()[:-n-1:-1] if reverse ordering is nesessary. -- Best regards Mikhail Golubev
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 05.06.2013 19:16, schrieb Михаил Голубев:
Hello,
It seems that I found micro bug in Python documentation describing collections.Counter class <http://docs.python.org/3.3/library/collections.html#counter-objects>. There is the following snippet of code
c.most_common()[:-n:-1] # n least common elements
Actually this expression returns not /n/ least common elements, but rather /n - 1,/ beacuse second boundary is not included (as usual with slices). You probably meant c.most_common()[-n:] orc.most_common()[:-n-1:-1] if reverse ordering is nesessary.
Hi Mikhail, thanks for the report; this is now fixed and will appear online soon. cheers, Georg -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.21 (GNU/Linux) iEYEARECAAYFAlJRPXYACgkQN9GcIYhpnLAtSgCaApE3cvKKFIhzGywsaeYgD6W3 cewAoLAFPh8sEA7HP5ulqF5w5L6p5gvg =vHAo -----END PGP SIGNATURE-----
participants (2)
-
Georg Brandl
-
Михаил Голубев