Creating a counter

Ian Kelly ian.g.kelly at gmail.com
Thu Oct 16 16:04:25 CEST 2014


On Thu, Oct 16, 2014 at 7:44 AM, Simon Kennedy <sffjunkie at gmail.com> wrote:
> When you looked through the other answers and found a solution you're happy with that does not use the standard library you can look through the documentation and find a stdlib (https://docs.python.org/2.7/library/index.html) provided way that may be slightly more elegant for counting strings.

I would have suggested a Counter if I thought it fit the OP's use
case. If you're listing directory contents, you're not going to have
any repeated strings, so all the counts will be 1, and your Counter
might as well be a list, which is what you got from calling
os.listdir() in the first place. So I was more inclined to think that
the OP was only trying to count one thing.

In any case, the question turned out to actually be about printing,
not counting.



More information about the Python-list mailing list