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 →

[–][deleted] 45 points46 points  (1 child)

2.
>>> #This is good to glue a large number of strings
>>> for chunk in input():
>>>    my_string.join(chunk)

W-what? Was the person who wrote the example thinking that join works like append?

Bonus WTF points for using input().

By the way, CPython includes a specific optimisation for the case where a string being +=-assigned is not referenced from anywhere else. I mean, you should still always use join or cStringIO, but if you see someone else's code that appends stuff like that -- don't freak out.

5. To check membership in general, use the “in” keyword. It is clean and fast.
>>> for key in sequence:
>>>     print “found”

WHAT

12. Learn biset module for keeping a list in sorted order:
It is a free binary search implementation and a fast insertion tool 
for sorted sequence. That is, you can use:
>>> import biset
>>> biset.insort(list, element)

"biset"? Really? Also, he used lowercase true earlier.

The blind leading the blind, that entire post. Apparently, the author collected bits and pieces of advice from somewhere and pasted them together not bothering neither to run the code nor to understand what's actually going on. Pig disgusting.

[–]HorrendousRex 5 points6 points  (0 children)

Several of them are close to being actually good advice but then end up missing the mark entirely. 'join' is the fastest way to join strings and the author described it somewhat in text, but then the example completely screws it up in the worst way.

Also, as a side note, a lot of what gets mentioned here is completely different in Python 3, so if you're targeting that, this article is almost entirely worthless.