[Python-ideas] get method for sets?
Greg Ewing
greg.ewing at canterbury.ac.nz
Thu May 17 05:03:11 CEST 2012
On 17/05/12 14:19, Paul Du Bois wrote:
> On Wed, May 16, 2012 at 5:56 PM, Cameron Simpson <cs at zip.com.au> wrote:
>> > def an(s):
>> > for i in s:
>> > return i
> Normally I'm content to lurk, but this thread has been going on for a
> long time without anyone pointing out that the "for" loop idiom needs
> an "else: raise KeyError" in order to act pythonically.
That depends on what result you want in the empty set case. If
returning None is okay, or you know the set can never be empty,
then it's fine as written.
--
Greg
More information about the Python-ideas
mailing list