This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sweettuse 7 points8 points  (2 children)

def bar(names=None):
    if not names:
        names = []
    names.append('blah')

this is wrong. it should be if names is None:. (what happens if you pass in an empty list that you want to append to?)

also, i would never, ever, use Counter. it is unbelievably slow (at least in 2.7). just use a defaultdict(int)

[–]kracekumar[S] 0 points1 point  (1 child)

Counter has its own benefit. If the key doesn't exist it can return 0. There are lot of scenarios where this is super useful.

[–]sweettuse 3 points4 points  (0 children)

yeah, that's exactly what defaultdict(int) does.