Re: [Python-Dev] slightly inconsistent set/list pop behaviour
Tennessee Leeuwenburg wrote: > Now, I know that sets aren't ordered, but... > > foo = set([1,2,3,4,5]) > bar = [1,2,3,4,5] > > foo.pop() will reliably return 1 > while bar.pop() will return 5 > > discuss :) As designed. If you play around a bit it becomes clear that what set.pop() returns is independent of the insertion order: PythonWin 2.5.2 (r252:60911, Mar 27 2008, 17:57:18) [MSC v.1310 32 bit (Intel)] on win32. >>> foo = set([5,4,3,2,1]) # Order reversed from above >>> foo.pop() 1 >>> foo = set([-1,0,1,2,3,4,5]) >>> foo.pop() 0 >>> foo = set([-1,1,2,3,4,5]) >>> foo.pop() 1 As the documentation says (http://docs.python.org/library/stdtypes.html#set.pop) set.pop() is free to return an arbitrary element. list.pop() however always returns the last element of the list, unless of course you specify some other index: http://docs.python.org/library/stdtypes.html#mutable-sequence-types, point 6. John ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Syntax suggestion for imports
Raymond Hettinger wrote: > How about a new, simpler syntax: > > * import threading or dummy_threading as threading > * import xml.etree.CElementTree or cElementTree or elementree.ElementTree as > ET > * from cStringIO or StringIO import StringIO These all look good to me. The "short circuit" import syntax and semantics are compact and intuitive. > * import readline or emptymodule This I find more problematic as "emptymodule" seems too magical. Even now any code that wants to use a module that might not have been successfully imported needs to check if that's the case. E.g., a fuller current use-case would be: try: readline = None import readline except ImportError: pass if readline is not None: readline.foo() ... Conceivably emptymodule could act as a Null object but that could create more problems than it solves. John ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com