rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
atol = res['Relative Tolerance'], rtol = res['Absolute Tolerance'], | rtol = res['Relative Tolerance'], atol = res['Absolute Tolerance'], | def fuseMesh(): """Fuse the nodes of a Mesh""" if not selection.check(): selection.ask() if not selection.names: return meshes = [ named(n) for n in selection.names ] res = askItems([ ('Relative Tolerance',1.e-5), ('Absolute Tolerance',1.e-5), ('Shift',0.5), ('Nodes per box',1)]) if not res: return before = [ m.nco... |
return Formex() | return Formex(empty((0,2,3,),dtype=float)) | def intersectionLinesWithPlane(F,p,n,atol=1.e-4): """Return the intersection lines of a plex-3 Formex with plane (p,n). F is a Formex of plexitude 3. p is a point specified by 3 coordinates. n is the normal vector to a plane, specified by 3 components. atol is a tolerance factor defining whether an edge is intersected... |
return Formex() F1 = F21 = F22 = F31 = F32 = F41 = F42= F43 = Formex(empty((0,2,3,),dtype=float)) | return Formex(empty((0,2,3,),dtype=float)) F1 = F21 = F22 = F31 = F32 = F41 = F42= F43 = Formex(empty((0,2,3,),dtype=float)) | def intersectionLinesWithPlane(F,p,n,atol=1.e-4): """Return the intersection lines of a plex-3 Formex with plane (p,n). F is a Formex of plexitude 3. p is a point specified by 3 coordinates. n is the normal vector to a plane, specified by 3 components. atol is a tolerance factor defining whether an edge is intersected... |
def transparent(state=None): | def transparent(state=True): | def transparent(state=None): toolbar.setTransparency(state) |
def perspective(state=None): | def perspective(state=True): | def perspective(state=None): toolbar.setPerspective(state) |
"""Perform a boolean operation with surface surf. | """Perform a boolean operation with surface surf. Both surfaces needs to be closed (border of a volume) and to be an orientable manifold (use fixNormals). | def boolean(self,surf,op,inter=False,check=False,verbose=False): """Perform a boolean operation with surface surf. |
if not globals().has_key('unique'): | try: unique([1],True) except TypeError: | def combinations(iterable, r): # combinations('ABCD', 2) --> AB AC AD BC BD CD # combinations(range(4), 3) --> 012 013 023 123 pool = tuple(iterable) n = len(pool) if r > n: return indices = range(r) yield tuple(pool[i] for i in indices) while True: for i in reversed(range(r)): if indices[i] != i + n - r: break else: r... |
res = askItems([('Number of static points',10),('Background',None,'radio',['Tiles','Structured points','Random points']),('Rotations',2),('Rotation angle',2),('Number of random points',300)]) | res = askItems([('Number of static points',10),('Background',None,'radio',{'choices':['Tiles','Structured points','Random points']}),('Rotations',2),('Rotation angle',2),('Number of random points',300)]) | def MotionInducedBlindness(): """Motion Induced Blindness This is a very nice illusion. Look at the centre of the image. The moving background will give the illusion that the other static points disappear. Blinking or changing your focus will immediately undo the effect. Cool huh? """ resetview('black') res = askItems... |
prefdir = os.path.dirname(pyformex.preffile) if not os.path.exists(prefdir): try: os.makedirs(prefdir) except: print("The path where your user preferences should be stored can not be created!\nPreferences are not saved!") return | def savePreferences(): """Save the preferences. The name of the preferences file is determined at startup from the configuration files, and saved in ``pyformex.preffile``. If a local preferences file was read, it will be saved there. Otherwise, it will be saved as the user preferences, possibly creating that file. If ... | |
reload(module) | def load(plugin): """Load the named plugin""" # imports are placed here to defer loading until possible import formex_menu import surface_menu import mesh_menu import tools_menu import draw2d import jobs_menu import postproc_menu module = globals().get(plugin,None) reload(module) if type(module) is ModuleType and hasat... | |
if type(div) == int: | div = asarray(div).ravel() if div.size == 1 and div.dtype.kind=='i': div = div[0] | def divide(self,div): """Divide a plex-2 Formex at the values in div. |
else: div = array(div).ravel() | def divide(self,div): """Divide a plex-2 Formex at the values in div. | |
p, il, it=surface.intersectSurfaceWithLines(s1, segm[:, 0], normalize(segm[:, 1]-segm[:, 0])) | p, il, it=intersectSurfaceWithLines(s1, segm[:, 0], normalize(segm[:, 1]-segm[:, 0])) | def intersectSurfaceWithSegments(s1, segm, atol=1.e-5): """it takes a TriSurface ts and a set of segments (-1,2,3) and intersect the segments with the TriSurface. It returns the points of intersections and, for each point, the indices of the intersected segment and triangle""" p, il, it=surface.intersectSurfaceWithLine... |
rev = connectivity(elems).inverse() | rev = connectivity.Connectivity(elems).inverse() | def removeTriangles(elems): """Remove the triangles from the centerline. This is a clean-up function for the centerline. Triangles appearing in the centerline are removed by this function. Both input and output are the connectivity of the centerline. """ rev = connectivity(elems).inverse() if rev.shape[1] > 2: w = wh... |
`elems` array, e.g. a list of element numbers. | `elems` array, e.g. a list of (integer) element numbers, or a boolean array with the same length as the `elems` array. | def select(self,selected): """Return a mesh with selected elements from the original. |
The returned mesh is not compacted. | The returned Mesh is not compacted. The complimentary operation is `unselect`. | def select(self,selected): """Return a mesh with selected elements from the original. |
def unselect(self, unselected): """Return a mesh without the unselected elements. """ wi=ones([self.nelems()]) wi[unselected]=0 return self.clip(wi) | def unselect(self, selected): """Return a mesh without the selected elements. This is the complimentary operation of `select`. - `selected`: an object that can be used as an index in the `elems` array, e.g. a list of (integer) element numbers, or a boolean array with the same length as the `elems` array. Returns a Me... | def unselect(self, unselected): """Return a mesh without the unselected elements. """ wi=ones([self.nelems()]) wi[unselected]=0 return self.clip(wi) |
This function is very convenient in clipping a TriSurface in a specified | This function is very convenient in clipping a Mesh in a specified | def test(self,nodes='all',dir=0,min=None,max=None,atol=0.): """Flag elements having nodal coordinates between min and max. |
Or directly use clip() or cclip() to create the clipped TriSurface | Or directly use clip() or cclip() to create the clipped Mesh | def test(self,nodes='all',dir=0,min=None,max=None,atol=0.): """Flag elements having nodal coordinates between min and max. |
"""Return a TriSurface with all the elements where t>0. | """Return a Mesh with all the elements where t>0. | def clip(self,t): """Return a TriSurface with all the elements where t>0. |
of elements of the TriSurface. The resulting TriSurface will contain all elements where t > 0. | of elements of the Mesh. The resulting Mesh will contain all elements where t > 0. | def clip(self,t): """Return a TriSurface with all the elements where t>0. |
"""This is the complement of clip, returning a TriSurface where t<=0. | """This is the complement of clip, returning a Mesh where t<=0. | def cclip(self,t): """This is the complement of clip, returning a TriSurface where t<=0. """ return self.select(t<=0) |
print item print type(item) | def add_items(self,items,form): """Add input items to form. | |
con = self.nodeConnections(self) | con = self.nodeConnections() | def pointNormals(self): """Compute the normal vectors at the points. The normal vector in a point is the average of the normal vectors of all the neighbouring triangles. The normal vectors are normalized before they are returned. """ # get list of elements connected to each point con = self.nodeConnections(self) NP = ... |
print("%s: %s" % (lead,str(s))) | try: if options.debug < 0 or (level>0 and options.debug % level > 0): raise pass except: print("%s: %s" % (lead,str(s))) | def debug(s,lead="DEBUG",level=0): """Print a debug message""" ## try: # to make sure that debug() can be used before options are set ## if options.debug < 0 or (level>0 and options.debug % level > 0): ## raise ## pass ## except: print("%s: %s" % (lead,str(s))) |
def selectmany(self, seq_selector, result_selector=None): def selectmany_gen(seq_selector, result_selector): | def select_many(self, seq_selector=None, result_selector=None): if not seq_selector: seq_selector = lambda x: x def select_many_gen(): | def selectmany(self, seq_selector, result_selector=None): def selectmany_gen(seq_selector, result_selector): for sub_seq in self: for item in seq_selector(sub_seq): if result_selector: yield result_selector(item) else: yield item return self.__class__(selectmany_gen(seq_selector, result_selector)) |
return self.__class__(selectmany_gen(seq_selector, result_selector)) | return self.__class__(select_many_gen()) | def selectmany_gen(seq_selector, result_selector): for sub_seq in self: for item in seq_selector(sub_seq): if result_selector: yield result_selector(item) else: yield item |
def takewhile(self, pred): def takewhile_gen(pred): | def take_while(self, pred): def take_while_gen(pred): | def takewhile(self, pred): def takewhile_gen(pred): i = iter(self) while True: item = i.next() if not pred(item): break yield item return self.__class__(takewhile_gen(pred)) |
return self.__class__(takewhile_gen(pred)) def skipwhile(self, pred): def skipwhile_gen(pred): | return self.__class__(take_while_gen(pred)) def skip_while(self, pred): def skip_while_gen(pred): | def takewhile_gen(pred): i = iter(self) while True: item = i.next() if not pred(item): break yield item |
return self.__class__(skipwhile_gen(pred)) | return self.__class__(skip_while_gen(pred)) | def skipwhile_gen(pred): i = iter(self) while True: item = i.next() if not pred(item): yield item break while True: yield i.next() |
def orderby(self, key_selector=None): def orderby_gen(): | def order_by(self, key_selector=None): def order_by_gen(): | def orderby(self, key_selector=None): def orderby_gen(): for item in sorted(self, key=key_selector): yield item return self.__class__(orderby_gen()) |
return self.__class__(orderby_gen()) thenby = orderby | return self.__class__(order_by_gen()) def reversed(self): return self.__class__(item for item in list(self)[::-1]) | def orderby_gen(): for item in sorted(self, key=key_selector): yield item |
def groupby(self, key_selector=None, val_selector=None): | def group_by(self, key_selector=None, val_selector=None): | def groupby(self, key_selector=None, val_selector=None): result = {} # this is greedy...but there's no other way to do it other than returning the same key # multiple times. key_selector = key_selector or (lambda item: item) val_selector = val_selector or (lambda item: item) for k, v in self.select(lambda item: (key_se... |
def tolist(self): | def to_list(self): | def tolist(self): return list(self) |
def todict(self, proj1=None, proj2=None): if proj1 and proj2: | def to_dict(self, key_selector=None, element_selector=None): if key_selector and element_selector: | def todict(self, proj1=None, proj2=None): if proj1 and proj2: return self \ .select(lambda item: (proj1(item), proj2(item))) \ .todict() elif proj1: return self \ .select(lambda item: (item, proj1(item))) \ .todict() else: return dict(self) |
.select(lambda item: (proj1(item), proj2(item))) \ .todict() elif proj1: | .select(lambda item: (key_selector(item), element_selector(item))) \ .to_dict() elif key_selector: | def todict(self, proj1=None, proj2=None): if proj1 and proj2: return self \ .select(lambda item: (proj1(item), proj2(item))) \ .todict() elif proj1: return self \ .select(lambda item: (item, proj1(item))) \ .todict() else: return dict(self) |
.select(lambda item: (item, proj1(item))) \ .todict() | .select(lambda item: (key_selector(item), item)) \ .to_dict() | def todict(self, proj1=None, proj2=None): if proj1 and proj2: return self \ .select(lambda item: (proj1(item), proj2(item))) \ .todict() elif proj1: return self \ .select(lambda item: (item, proj1(item))) \ .todict() else: return dict(self) |
def firstordefault(self, pred=None, default=None): | def first_or_default(self, pred=None, default=None): | def firstordefault(self, pred=None, default=None): try: return self.first(pred) except ValueError: return default |
def lastordefault(self, pred=None, default=None): | def last_or_default(self, pred=None, default=None): | def lastordefault(self, pred=None, default=None): try: return self.last(pred) except ValueError: return default |
def singleordefault(self, pred=None, default=None): | def single_or_default(self, pred=None, default=None): | def singleordefault(self, pred=None, default=None): if pred: return self.where(pred).singleordefault(default=default) else: result = no_result = object() i = iter(self) try: result = i.next() except StopIteration: return default try: i.next() raise ValueError('Sequence contains more than one item') except StopIteration... |
return self.where(pred).singleordefault(default=default) | return self.where(pred).single_or_default(default=default) | def singleordefault(self, pred=None, default=None): if pred: return self.where(pred).singleordefault(default=default) else: result = no_result = object() i = iter(self) try: result = i.next() except StopIteration: return default try: i.next() raise ValueError('Sequence contains more than one item') except StopIteration... |
def elementat(self, index): | def element_at(self, index): | def elementat(self, index): for idx, item in enumerate(self): if idx == index: return item raise IndexError('No item with index {0}'.format(index)) |
pass | def join(self, inner, outer_key, inner_key, result): inner_items = inner \ .group_by(inner_key) \ .to_dict(lambda (k, g): k, lambda (k, g): g) return Query(self .where(lambda i: outer_key(i) in inner_items) .select_many(lambda i: inner_items[outer_key(i)], result)) | def count(self, pred=None): if pred: return self.where(pred).count() else: count = 0 for item in self: count += 1 return count |
pass | @staticmethod def repeat(value): def repeat_gen(): while True: yield value return Query(repeat_gen()) def concat(self, other): def concat_gen(): for item in self: yield item for item in other: yield item return self.__class__(concat_gen()) def zip(self, other, selector=None): def zip_gen(): iter1 = iter(self) iter2 = i... | def count(self, pred=None): if pred: return self.where(pred).count() else: count = 0 for item in self: count += 1 return count |
print class_.__name__ | print color(color.FG_BROWN, color.BOLD) + class_.__name__ + color(color.DEFAULT) | def run_tests(*classes): tests_ok, tests_fail, tests_ran, failed = 0, 0, 0, [] for class_ in classes: print class_.__name__ ok, fail, ran = class_().run() tests_ok += ok tests_fail += fail tests_ran += ran if fail: failed += [class_.__name__] print print 'ok: {0}/{2}; fail: {1}/{2}; failing: {3}'.format( tests_ok, test... |
print ' ', method.__name__, | def run(self): methods = [ getattr(self, name) for name in sorted(dir(self)) #if name.startswith('test_') if callable(getattr(self, name)) if hasattr(getattr(self, name), 'is_test') ] tests_ok = 0 tests_fail = 0 tests_total = len(methods) for method in methods: print ' ', method.__name__, try: result = method() print ... | |
print | print ' ' + color(color.FG_GREEN, color.BOLD) + method.__name__ + color(color.DEFAULT) | def run(self): methods = [ getattr(self, name) for name in sorted(dir(self)) #if name.startswith('test_') if callable(getattr(self, name)) if hasattr(getattr(self, name), 'is_test') ] tests_ok = 0 tests_fail = 0 tests_total = len(methods) for method in methods: print ' ', method.__name__, try: result = method() print ... |
print ex | print ' ' + color(color.FG_RED, color.BOLD) + method.__name__ + color(color.DEFAULT) \ + ' ' + str(ex) | def run(self): methods = [ getattr(self, name) for name in sorted(dir(self)) #if name.startswith('test_') if callable(getattr(self, name)) if hasattr(getattr(self, name), 'is_test') ] tests_ok = 0 tests_fail = 0 tests_total = len(methods) for method in methods: print ' ', method.__name__, try: result = method() print ... |
print '{0} -- ok: {1}/{3}; failed: {2}/{3}'.format( type(self).__name__, tests_ok, tests_fail, tests_total) | def run(self): methods = [ getattr(self, name) for name in sorted(dir(self)) #if name.startswith('test_') if callable(getattr(self, name)) if hasattr(getattr(self, name), 'is_test') ] tests_ok = 0 tests_fail = 0 tests_total = len(methods) for method in methods: print ' ', method.__name__, try: result = method() print ... | |
return Query(self.L).where(lambda n: n % 2 == 0).tolist() | return Query(self.L) \ .where(lambda n: n % 2 == 0) \ .to_list() | def where(self): return Query(self.L).where(lambda n: n % 2 == 0).tolist() |
return Query(self.L).select(lambda n: n * 2).tolist() | return Query(self.L) \ .select(lambda n: n * 2) \ .to_list() | def select(self): return Query(self.L).select(lambda n: n * 2).tolist() |
def selectmany_1(self): | def select_many_1(self): | def selectmany_1(self): return Query(self.W1) \ .selectmany(lambda s: s.split(' ')) \ .tolist() |
.selectmany(lambda s: s.split(' ')) \ .tolist() | .select_many(lambda s: s.split(' ')) \ .to_list() | def selectmany_1(self): return Query(self.W1) \ .selectmany(lambda s: s.split(' ')) \ .tolist() |
def selectmany_2(self): | def select_many_2(self): | def selectmany_2(self): return Query(self.W1) \ .selectmany(lambda s: s.split(' '), lambda s: s[1:]) \ .tolist() |
.selectmany(lambda s: s.split(' '), lambda s: s[1:]) \ .tolist() | .select_many(lambda s: s.split(' '), lambda s: s[1:]) \ .to_list() | def selectmany_2(self): return Query(self.W1) \ .selectmany(lambda s: s.split(' '), lambda s: s[1:]) \ .tolist() |
def selectmany_3(self): | def select_many_3(self): | def selectmany_3(self): return Query(self.W2) \ .selectmany(lambda sx: sx) \ .tolist() |
.selectmany(lambda sx: sx) \ .tolist() | .select_many(lambda sx: sx) \ .to_list() | def selectmany_3(self): return Query(self.W2) \ .selectmany(lambda sx: sx) \ .tolist() |
def selectmany_4(self): | def select_many_4(self): | def selectmany_4(self): return Query(self.W1) \ .select(lambda s: s.split(' ')) \ .selectmany() \ .tolist() |
.selectmany() \ .tolist() | .select_many() \ .to_list() | def selectmany_4(self): return Query(self.W1) \ .select(lambda s: s.split(' ')) \ .selectmany() \ .tolist() |
return Query(self.L).take(3).tolist() | return Query(self.L).take(3).to_list() | def take(self): return Query(self.L).take(3).tolist() |
return Query(self.L).skip(7).tolist() | return Query(self.L).skip(7).to_list() | def skip(self): return Query(self.L).skip(7).tolist() |
def takewhile(self): return Query(self.L).takewhile(lambda n: n < 4).tolist() | def take_while(self): return Query(self.L).take_while(lambda n: n < 4).to_list() | def takewhile(self): return Query(self.L).takewhile(lambda n: n < 4).tolist() |
def skipwhile(self): return Query(self.L).skipwhile(lambda n: n < 8).tolist() | def skip_while(self): return Query(self.L).skip_while(lambda n: n < 8).to_list() | def skipwhile(self): return Query(self.L).skipwhile(lambda n: n < 8).tolist() |
def orderby_1(self): | def order_by_1(self): | def orderby_1(self): return Query(self.R1) \ .orderby() \ .tolist() |
.orderby() \ .tolist() | .order_by() \ .to_list() | def orderby_1(self): return Query(self.R1) \ .orderby() \ .tolist() |
def orderby_2(self): | def order_by_2(self): | def orderby_2(self): return Query(self.R1) \ .orderby(lambda n: n) \ .tolist() |
.orderby(lambda n: n) \ .tolist() | .order_by(lambda n: n) \ .to_list() | def orderby_2(self): return Query(self.R1) \ .orderby(lambda n: n) \ .tolist() |
def thenby_1(self): | def then_by_1(self): | def thenby_1(self): return Query(self.R2) \ .orderby(lambda n: n[0]) \ .thenby(lambda n: n[1]) \ .tolist() |
.orderby(lambda n: n[0]) \ .thenby(lambda n: n[1]) \ .tolist() | .order_by(lambda n: n[0]) \ .then_by(lambda n: n[1]) \ .to_list() | def thenby_1(self): return Query(self.R2) \ .orderby(lambda n: n[0]) \ .thenby(lambda n: n[1]) \ .tolist() |
def groupby(self): | def group_by(self): | def groupby(self): return Query(self.G) \ .groupby(lambda s: s[0]) \ .select(lambda (key, items): (key, items.tolist())) \ .todict() |
.groupby(lambda s: s[0]) \ .select(lambda (key, items): (key, items.tolist())) \ .todict() | .group_by(lambda s: s[0]) \ .select(lambda (key, items): (key, items.to_list())) \ .to_dict() | def groupby(self): return Query(self.G) \ .groupby(lambda s: s[0]) \ .select(lambda (key, items): (key, items.tolist())) \ .todict() |
.tolist() | .to_list() | def distinct(self): return Query([2,2,3,5,5]) \ .distinct() \ .tolist() |
.tolist() | .to_list() | def union(self): return Query(self.S1) \ .union(Query(self.S2)) \ .tolist() |
.tolist() | .to_list() | def interect(self): return Query(self.S1) \ .intersect(Query(self.S2)) \ .tolist() |
.tolist() | .to_list() | def difference(self): return Query(self.S1) \ .difference(Query(self.S2)) \ .tolist() |
def todict_1(self): | def to_dict_1(self): | def todict_1(self): return Query(self.L) \ .where(lambda n: n <= 4) \ .select(lambda n: (n, 2*n)) \ .todict() |
.todict() @returns({1:2, 2:4, 3:6, 4:8}) def todict_2(self): | .to_dict() @returns({2:1, 4:2, 6:3, 8:4}) def to_dict_2(self): | def todict_1(self): return Query(self.L) \ .where(lambda n: n <= 4) \ .select(lambda n: (n, 2*n)) \ .todict() |
.todict(lambda n: 2 * n) | .to_dict(lambda n: 2 * n) | def todict_2(self): return Query(self.L) \ .where(lambda n: n <= 4) \ .todict(lambda n: 2 * n) |
def todict_3(self): | def to_dict_3(self): | def todict_3(self): return Query(self.L) \ .where(lambda n: n <= 4) \ .todict(lambda n: 2 * n, lambda n: 3 * n) |
.todict(lambda n: 2 * n, lambda n: 3 * n) | .to_dict(lambda n: 2 * n, lambda n: 3 * n) | def todict_3(self): return Query(self.L) \ .where(lambda n: n <= 4) \ .todict(lambda n: 2 * n, lambda n: 3 * n) |
def elementat_1(self): return Query(self.L).elementat(0) | def element_at_1(self): return Query(self.L).element_at(0) | def elementat_1(self): return Query(self.L).elementat(0) |
def elementat_2(self): return Query(self.L).elementat(9) | def element_at_2(self): return Query(self.L).element_at(9) | def elementat_2(self): return Query(self.L).elementat(9) |
def firstordefault_1(self): return Query(self.L).firstordefault() | def first_or_default_1(self): return Query(self.L).first_or_default() | def firstordefault_1(self): return Query(self.L).firstordefault() |
def firstordefault_2(self): return Query(self.E).firstordefault(default=42) | def first_or_default_2(self): return Query(self.E).first_or_default(default=42) | def firstordefault_2(self): return Query(self.E).firstordefault(default=42) |
def singleordefault_1a(self): return Query(self.L).where(lambda n: n == 4).singleordefault(default=42) | def single_or_default_1a(self): return Query(self.L).where(lambda n: n == 4).single_or_default(default=42) | def singleordefault_1a(self): return Query(self.L).where(lambda n: n == 4).singleordefault(default=42) |
def singleordefault_1b(self): return Query(self.L).where(lambda n: n > 10).singleordefault(default=42) @raises(ValueError) def singleordefault_1c(self): return Query(self.L).where(lambda n: n < 4).singleordefault(default=42) @raises(ValueError) def singleordefault_1d(self): return Query(self.L).where(lambda n: n >= 4).... | def single_or_default_1b(self): return Query(self.L).where(lambda n: n > 10).single_or_default(default=42) @raises(ValueError) def single_or_default_1c(self): return Query(self.L).where(lambda n: n < 4).single_or_default(default=42) @raises(ValueError) def single_or_default_1d(self): return Query(self.L).where(lambda n... | def singleordefault_1b(self): return Query(self.L).where(lambda n: n > 10).singleordefault(default=42) |
def singleordefault_2a(self): return Query(self.L).singleordefault(lambda n: n == 4, default=42) | def single_or_default_2a(self): return Query(self.L).single_or_default(lambda n: n == 4, default=42) | def singleordefault_2a(self): return Query(self.L).singleordefault(lambda n: n == 4, default=42) |
def singleordefault_2b(self): return Query(self.L).singleordefault(lambda n: n > 10, default=42) @raises(ValueError) def singleordefault_2c(self): return Query(self.L).singleordefault(lambda n: n < 4, default=42) @raises(ValueError) def singleordefault_2d(self): return Query(self.L).singleordefault(lambda n: n >= 4, de... | def single_or_default_2b(self): return Query(self.L).single_or_default(lambda n: n > 10, default=42) @raises(ValueError) def single_or_default_2c(self): return Query(self.L).single_or_default(lambda n: n < 4, default=42) @raises(ValueError) def single_or_default_2d(self): return Query(self.L).single_or_default(lambda n... | def singleordefault_2b(self): return Query(self.L).singleordefault(lambda n: n > 10, default=42) |
.join(['AB', 'BB', 'CB'], lambda a: a[0], lambda b: b[0], lambda a, b: (a,b)) \ .tolist() | .join( Query(['AB', 'BB', 'CB']), lambda a: a[0], lambda b: b[0], lambda (a,b): (a,b)) \ .to_list() | def join(self): return Query(['AA', 'BA', 'CA']) \ .join(['AB', 'BB', 'CB'], lambda a: a[0], lambda b: b[0], lambda a, b: (a,b)) \ .tolist() |
def elementatordefault_1(self): return Query(self.L).elementatordefault(1, default=42) | def element_at_or_default_1(self): return Query(self.L) \ .element_at_or_default(0, default=42) | def elementatordefault_1(self): return Query(self.L).elementatordefault(1, default=42) |
def elementatordefault_2(self): return Query(self.L).elementatordefault(0, default=42) | def element_at_or_default_2(self): return Query(self.L) \ .element_at_or_default(11, default=42) | def elementatordefault_2(self): return Query(self.L).elementatordefault(0, default=42) |
def defaultifempty_1(self): return Query(self.L).defaultifempty(default=[42]).tolist() | def default_if_empty_1(self): return Query(self.L) \ .default_if_empty(default=[42]) \ .to_list() | def defaultifempty_1(self): return Query(self.L).defaultifempty(default=[42]).tolist() |
def defaultifempty_2(self): return Query(self.E).defaultifempty(default=[42]).tolist() | def default_if_empty_2(self): return Query(self.E) \ .default_if_empty(default=[42]) \ .to_list() | def defaultifempty_2(self): return Query(self.E).defaultifempty(default=[42]).tolist() |
def oftype(self): return Query([1, "Foo", 2, "Bar"]).oftype(str).tolist() | def of_type(self): return Query([1, "Foo", 2, "Bar"]) \ .of_type(str) \ .to_list() | def oftype(self): return Query([1, "Foo", 2, "Bar"]).oftype(str).tolist() |
return Query(self.L).reversed().tolist() | return Query(self.L) \ .reversed() \ .to_list() | def reversed(self): return Query(self.L).reversed().tolist() |
return Query([1,2,3]).concat([4,5,6]).tolist() @returns([(1,3),(2,4),(3,5)]) def zip(self): return Query([1,2,3]).zip([4,5,6], lambda a,b: (a,b)) | return Query([1,2,3]) \ .concat([4,5,6]) \ .to_list() @returns([(1,4),(2,5),(3,6)]) def zip_1(self): return Query([1,2,3]) \ .zip([4,5,6]) \ .to_list() @returns([(1,4),(2,5),(3,6)]) def zip_2(self): return Query([1,2,3]) \ .zip([4,5,6], lambda a, b: (a,b)) \ .to_list() | def concat(self): return Query([1,2,3]).concat([4,5,6]).tolist() |
return Query.repeat(6).take(3).tolist() | return Query.repeat(6) \ .take(3) \ .to_list() | def repeat(self): return Query.repeat(6).take(3).tolist() |
def sequenceequal(self): return Query(self.L).sequenceequal(self.L) | def sequence_equal(self): return Query(self.L).sequence_equal(self.L) import sys if len(sys.argv) >= 1 and sys.argv[1] == '--mono': color.ENABLED = False | def sequenceequal(self): return Query(self.L).sequenceequal(self.L) |
for b in xrange(1, n): | for b in xrange(a, n): | def euler_009(n): for a in xrange(1, n): for b in xrange(1, n): if a + b >= n: break c = n - a - b if a ** 2 + b ** 2 == c ** 2: return a * b * c |
fields = ('allow_contact', 'preferred_language') | fields = ('allow_contact', 'preferred_language', 'tags') | def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=':', empty_permitted=False, instance=None): ModelForm.__init__(self, data, files, auto_id, prefix, initial, error_class, label_suffix, empty_permitted, instance) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.