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

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 ;)
participants (3)
-
Andreas Jung
-
Jens
-
Michael Ströder