News for hackers. Stuff that matters.
Re:Python idiom for taking the single item from a list by torrentabuse on Monday September 27, 2010 @02:32PM (#1732784)
Proposed style guide:

When you want to get the (n+1)th item from a list, do:

item = stuff[n]

To get the first item, do:

item = stuff[0]

Unless the list has one element, then do:

(item, ) = stuff

At least you'll never be accused of consistency.

Re:Python idiom for taking the single item from a list by StavrosK on Monday September 27, 2010 @02:37PM (#1732806)
Not really. The first two are consistent, but the last one is "get the only item and assert that there is only one item to get. If you don't care about the assertion, use [0], as always. I like the latter, because there's added info for the reader ("this should return a one-item iterable").

It's not really inconsistent, because you aren't performing the same operation in the two cases.

Re:Python idiom for taking the single item from a list by spoondan on Tuesday September 28, 2010 @01:49AM (#1734722)
I'm annoyed by the belief that consistency is ipso facto good. Consistency is a tool for attacking a particular type of problem. Consistency for its own sake will often make things worse.

I see this fallacious reasoning all the time in design critiques: this is inconsistent with that. Well, yes, but so what? Why is consistency desirable in this instance?