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.
...return a list of nodes (including the start and end nodes) comprising the path. When no path can be found, it returns None. The same node will not occur more than once on the path returned (i.e. it won't contain cycles). The algorithm uses an important technique called backtracking: it tries each possibility in turn until it finds a solution. def find_path(graph, start, end, path=[]): path = path + [start] if start == end: return path if n...
...return Norwitz reported that we failed to file a federal tax return, IRS Form 990, by the May 15 deadline. There is a $20/day late fee. We are not required to file a tax return, but we can choose to file one. Next year, we will be required to file because of the amount of revenue from PyCon. Last year, we filed the return late, because we wanted to have a return on file when we submitted our application for charity status. The board recommended that Norwitz prepare a return and make it avai...
...return map(ord, string) and the somewhat less obvious: import array def g2(string): return array.array('b', string).tolist() Timing these reveals that g2() is about five times as fast as g1(). There's a catch though: g2() returns integers in the range -128..127, while g1() returns integers in the range 0..255. If you need the positive integers, g1() is going to be faster than anything postprocessing you could do on the result from g2(). (Note: since this e...
...returns more information than it used to do in 2.1. For example, dir([]) also reports the special methods that overload various operators ('__add__', '__getitem__', '__len__', etc.) as well as '__class__'. For classes (classic as well as new-style), it returns the attributes of the class as well as of the base classes. <p><li>The special attributes __members__ and __methods__ are no longer supported (for most built-in types). Use the new and improved dir() function instead. <p&...
...return scaleX(d.x); }) .attr("y", function(d) { return scaleY(d.y) + chartOptions.margin; }) .attr("height", function(d) { return yAxisLength - scaleY(d.y); }) .attr("width", function(d){ return barWidth; }) svg.append("g").selectAll("text") .data(initData) .enter() .append("text") .attr("class", "bar-label") .attr("x", function(d) { return scaleX(d.x) + 20 }) .attr("y", function(d) { return scaleY(d.y) + 35 }) .text(functio...
...return an object. There's nothing that requires that it return a new object that is an instance of its class argument, although that is the convention. If you return an existing object, the constructor call will still call its __init__ method. If you return an object of a different class, its __init__ method will be called. If you forget to return something, Python will unhelpfully return None, and your caller will probably be very confused. For immutable classes, your __new__ may r...
...return an object. There's nothing that requires that it return a new object that is an instance of its class argument, although that is the convention. If you return an existing object of your class or a subclass, the constructor call will still call its __init__ method. If you return an object of a different class, its __init__ method will not be called. If you forget to return something, Python will unhelpfully return None, and your caller will probably be very confused. For immut...
...return (if you are required to file one) available for public inspection for three years after the due date of the return. You can charge only a reasonable fee for reproduction and actual postage costs for the copied materials. The law does not require you to provide copies of public inspection documents that are widely available, such as by posting them on the Internet (World Wide Web). You may be liable for a penalty of $20 a day for each day you do not make these documents available ...
...return a number too big for an integer will automatically return a long integer. (PEP 237) generator expressions - generator expressions are similar to a list comprehension, but instead of creating the entire list of results they create a generator that returns the results one by one. This allows for efficient handling of very large lists. (PEP 289) reversed() - a new builtin that takes a sequence and returns an iterator that loops over the elements of the sequence in reverse order (PEP 322) new...
...returns a dict whose keys are taken from the given iterable (the values default to None). Also a new dict method was added, pop(key), which removes and returns the value corresponding to the given key. filter() - now returns Unicode when the input is Unicode. Various bugs with subclasses of built-in types fixed. (New in 2.3a2.) int() - this can now return a long when converting a string with many digits, rather than raising OverflowError. (New in 2.3a2: issues a FutureWarning when sign-foldin...
...return Instance(self) class Instance: def __init__(self, klass): self.__klass__ = klass def __getattr__(self, name): try: value = self.__klass__.__namespace__[name] except KeyError: raise AttributeError, name if type(value) is not types.FunctionType: return value return BoundMethod(value, self) class BoundMethod: def __init__(self, function, instance): self.function = function ...
...returns a duration, ValueError is raised if tz.dst(dt) returns None (2.3a1 treated it as 0 instead, but a tzinfo subclass wishing to participate in time zone conversion has to take a stand on whether it supports DST; if you don't care about DST, then code dst() to return 0 minutes, meaning that DST is never in effect). The tzinfo methods utcoffset() and dst() must return a timedelta object (or None) now. In 2.3a1 they could also return an int or long, but that was an unhelpfully redundant lefto...
...returning an error instead). What's New in Python 3.0a2? Release date: 07-Dec-2007 (Note: this list is incomplete.) Core and Builtins str8 now has the same construction signature as bytes. Comparisons between str and str8 now return False/True for ==/!=. sqlite3 returns str8 when recreating on object from it's __conform__ value. The struct module returns str8 for all string-related formats. This was true before this change, but becomes more apparent thanks to string comparisons always be...
If you didn't find what you need, try your search in the Python language documentation.