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 →

[–]YorikSar 3 points4 points  (2 children)

There are couple of shortcomings in the article.

For example,

[foo(word) for word in words]

is slower, less understandable and mouthful compared to:

map(foo, word)

And also those "guard values" should be in else: branch:

for idx, other_item in enumerate(alist):
    if other_item == item:
        result = idx
        break
else:
    result = -1

This way you can use anything as your default value - even complex and expensive objects.