Notice: While JavaScript is not essential for this website, your interaction with the content will be limited. Please turn JavaScript on for the full experience.
...len(q): at = q.popleft() for next in graph[at]: if next not in dist: dist[next] = [dist[at], next] q.append(next) return dist.get(end) Note that this returns the path in a weird format, e.g., [[['A'], 'B'], 'D']. In particular, len(find_shortest_path(graph, 'A', 'D')) will give the incorrect answer (2, because the outer list is of length 2). This is because append is done as [dist[at], next] in...
...lenty of implementations in pure Python available (including Demo/classes/Rat.py). PEP 240 - Adding a Rational Literal to Python - Zadka Given my comments on 239, I propose to reject this. PEP 242 - Numeric Kinds - Dubois Nobody except the author seems to be interested in pursueing this. Personally, I think the idea is not particularly Pythonic -- the trend is towards fewer numeric types, nor more (see PEP 237). I believe the author has said that it would be better to retrac...
...lent to omitting it. In particular, the statement raise class, None is equivalent to raise class() and not to raise class(None) Likewise, the statement raise class, value where value happens to be a tuple is equivalent to passing the tuple's items as individual arguments to the class constructor, rather than passing value as a single argument (and an empty tuple calls the constructor without arguments). This makes a difference because there's a difference betwee...
...len(seq))" problem more elegantly. (PEP 279) basestring - an abstract string type which is the base class for str (8-bit strings) and unicode. Primarily used to simplify tests for string-ness to isinstance(x, basestring). bool, True, False - these were introduced as ints in Python 2.2.1, but are now a separate type (a subtype of int). This means that True and False are now printed as the strings 'True' and 'False', respectively. As of 2.3b1, bool() without arguments returns False. (PEP ...
...lently accept the first case-insensitive match of any kind; raise ImportError if none found. Else search sys.path for the first case-sensitive match; raise ImportError if none found. The same rules have been implented on other platforms with case- insensitive but case-preserving filesystems too (including Cygwin, and several flavors of Macintosh operating systems). winsound module: Under Win9x, winsound.Beep() now attempts to simulate what it's supposed to do (and does do under NT and 2000) v...
...lent to: a**b. operator.is_(a,b) which is equivalent to: a is b. operator.is_not(a,b) which is equivalent to: a is not b. posix.openpty now works on all systems that have /dev/ptmx. A module zipimport exists to support importing code from zip archives. The new datetime module supplies classes for manipulating dates and times. The basic design came from the Zope "fishbowl process", and favors practical commercial applications over calendar esoterica. See http://www.zope.org/M...
...len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__repr__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__str__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> The new dir() gives more information than the old one: in addition to the names of instance variables and regular methods, it also shows the methods that are normally invoked through special notations, like __iadd__ (+=), __len__ (len...
...len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__repr__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__str__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> The new dir() gives more information than the old one: in addition to the names of instance variables and regular methods, it also shows the methods that are normally invoked through special notations, like __iadd__ (+=), __len__ (len), __ne__ (!=). M...
...length_hint__ instead of __len__. Behavior now matches other reversed iterators. Issue #4367: Python would segfault during compiling when the unicodedata module couldn't be imported and N escapes were present. Fix build failure of _cursesmodule.c building with -D_FORTIFY_SOURCE=2. Library Issue #4387: binascii now refuses to accept str as binary input. Issue #4073: Add 2to3 support to build_scripts, refactor that support in build_py. IDLE would print a "Unhandled server exception!"...
...lendars In order to make it easier for the community to find Python related events, I've setup a team of volunteers to manage two new event calendars. One for larger events and another one for smaller events: Python events calendar Python user group events calendar The calendars are displayed on the http://pycon.org/ site and in the sidebar of http://python.org/. Details about the calendars are available on the wiki page we have for them: http://wiki.python.org/moin/PythonEventsCalendar ...
If you didn't find what you need, try your search in the Python language documentation.