Re: [Python-de] Bessere Doku für collections.Counter
Christopher Arndt wrote:
Am 28.01.2015 um 21:22 schrieb Andreas Jung:
Was soll an der Doku verkehrt sein?
Ich weiß auch nicht, was daran falsch ist, aber zumindest dieses Beispiel
>>> c = Counter('gallahad') # a new counter from an iterable
kann, wenn man sich nicht bewusst macht, dass Strings auch Iterables sind, flasche Vorstellungen über das Ergebnis provozieren. Dass da dieses rauskommt:
>>> c.keys() dict_keys(['a', 'l', 'd', 'h', 'g'])
hätte man evtl. auch zeigen sollen.
Nun ja, mir hat das geholfen:
c = Counter('gallahad') c Counter({'a': 3, 'l': 2, 'h': 1, 'g': 1, 'd': 1})
Vielleicht wäre ein Kommentar dieser Art hilfreich: "This example counts occurences of all letters in the string (which is a iterable)." Ähnliche Kommentare an anderen Stellen. Ciao, Michael.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 https://docs.python.org/devguide/docquality.html Michael Ströder wrote:
Christopher Arndt wrote:
Am 28.01.2015 um 21:22 schrieb Andreas Jung:
Was soll an der Doku verkehrt sein? Ich weiß auch nicht, was daran falsch ist, aber zumindest dieses Beispiel
c = Counter('gallahad') # a new counter from an iterable
kann, wenn man sich nicht bewusst macht, dass Strings auch Iterables sind, flasche Vorstellungen über das Ergebnis provozieren. Dass da dieses rauskommt:
c.keys() dict_keys(['a', 'l', 'd', 'h', 'g'])
hätte man evtl. auch zeigen sollen.
Nun ja, mir hat das geholfen:
c = Counter('gallahad') c Counter({'a': 3, 'l': 2, 'h': 1, 'g': 1, 'd': 1})
Vielleicht wäre ein Kommentar dieser Art hilfreich:
"This example counts occurences of all letters in the string (which is a iterable)."
Ähnliche Kommentare an anderen Stellen.
Ciao, Michael. _______________________________________________ python-de maillist - python-de@python.org https://mail.python.org/mailman/listinfo/python-de
- -- Regards Andreas Jung andreas@andreas-jung.com about.me/andreasjung -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQGUBAEBAgAGBQJUyc0/AAoJEADcfz7u4AZj0RELvR0pYj0sS4XiFdKzPwRAbdKZ 75hb783ty3r0AKHw66Odps/Qc8t+eVRpX5g9sVFIBVn94g/Mp6HEID9AJZhtNa5t LBQwQ8cs2GAsK5AtEFcuUYV0TEUIBMKzxy7xzYXJrXRr/L30Q88zpiQ8vBlw0IG0 jshFCAYYgtBV451v+uLYyU3VOy7CL1BKi4+ed0KhW2wBFGpE46K9F0fTSujRq1DN i7xFuX/KihBhZjJShWuZH4tzWOS7M+yKxRpkEInNxieqD43CcLbatkB0MPJyrt6d gghNCj/ezbILcF6Dr8EylilTJJWdnF8eSup2E8vqV6Z57a+NZb6y/UMcTlBlDCMS +mtRMevHadmkXR9DTwheAgyVxXN0J9HYHz/nVYFS+Ec8kDRj3eUCB9joiU2Iwvrz dFlLtt7iqKW44bDyOCSgKdxUfHWDqYqODXBqfXT9nkWgUrBI9fz+YaulLig6X1+T +nJPPoOq1A71GrvUYTHfMiZh1x0LQh8= =PD9T -----END PGP SIGNATURE-----
Am 28.01.2015 um 22:42 schrieb Michael Ströder:
c = Counter('gallahad') c Counter({'a': 3, 'l': 2, 'h': 1, 'g': 1, 'd': 1})
Vielleicht wäre ein Kommentar dieser Art hilfreich:
"This example counts occurences of all letters in the string (which is a iterable)."
Ähnliche Kommentare an anderen Stellen.
Also ich bin lieber für Beispiele, weil man die schneller erfassen kann, als Text. Deshalb kann man sich dann die Kommentare auch ganz sparen ;) Also warum nicht das hier: """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
c = Counter() # a new, empty counter c = Counter('gallahad') # a new counter from an iterable c = Counter({'red': 4, 'blue': 2}) # a new counter from a mapping c = Counter(cats=4, dogs=8) # a new counter from keyword args """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Ändern in: """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
c = Counter() # a new, empty counter Counter() Counter('gallahad') # a new counter from an iterable Counter({'a': 3, 'l': 2, 'h': 1, 'g': 1, 'd': 1}) c = Counter({'red': 4, 'blue': 2}) # a new counter from a mapping Counter({'red': 4, 'blue': 2}) c = Counter(cats=4, dogs=8) # a new counter from keyword args Counter({'dogs': 8, 'cats': 4}) """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Klar, wenn man Counter kennt, dann ist das Überflüssig. Aber dann schaue ich auch nicht in die Doku dazu rein ;) -- Mfg. Jens Diemer ---- http://www.jensdiemer.de
participants (3)
-
Andreas Jung
-
Jens
-
Michael Ströder