Hopefully sufficiently documented to stand without introduction:
def getclassdistance(srcs, dst):
"""srcs may be either a single class or a list of (class, distance) pairs.
dst is the superclass to find.
Performs a breadth-first search for dst, returning the shortest distance.
if type(srcs) != list:
srcs = [(srcs, 0)]
if len(srcs) == 0:
here, distance = srcs
if here == dst:
newSrc = srcs[1:] + [(c, distance + 1) for c in list(here.__bases__)]
return classDistance(newSrc, dst)
If this is already implemented and I just couldn't find it, I'm more
than happy to withdraw the idea.
Nova Engineer, HP Cloud. AKA lealexis, lxsli.
I would like to purpose that in python 3 it will be easy to chain and slice
Iterators just like you can add and slice lists and tuples easily.
I think there could be 2 methods to do this:
1. Implementing '+' and slicing ([1:2:3]) for iterators and generators by
default, Resulting in Itertool's chain(a,b) and islice(a,b,c) respectively.
2. Having itertool's chain and islice imported by default.
I think since python 3 return zip,map, dict.items and so on as iterators,
it makes working with those kind of objects more difficult without having
these methods around. And since those methods are important enough to have
for lists, it seems important enough for iterators too.