Language design

Chris Angelico rosuav at gmail.com
Wed Sep 11 10:46:02 EDT 2013


On Thu, Sep 12, 2013 at 12:32 AM, Neil Cerutti <neilc at norwich.edu> wrote:
> On 2013-09-11, Burak Arslan <burak.arslan at arskom.com.tr> wrote:
>> My favourite gotcha is this:
>>
>>     elt, = elts
>>
>> It's a nice and compact way to do both:
>>
>>     assert len(elts) == 0
>>     elt = elts[0]
>
> I'm confused. Your rewrite looks like an assertion error or an
> IndexError.

Presumably he meant to assert that the length is 1. If elts is a list,
then yes, these are equivalent, though the expanded form is actually a
bit different (since any iterable can be used).

ChrisA



More information about the Python-list mailing list