On Wednesday, October 5, 2016 at 12:51:59 PM UTC-7, Joe Barnhart wrote: > > One Python helper I find enormously useful is "extend()" as applied to > list objects. Extend differs from append in that it adds the items of the > list provided at the same level as the current list items, thereby > "extending" the list. >
I'll try paraphrasing to see if I understand you and the examples: given 2 lists, [a0, a1, .., an] and [b0, b1, ..., bn], you want the elements of b to be concantenated to the a list, rather than putting a single item consistenting of the b list at the end of the a list. Roughly for item in b: a.append(item) Did I get it? > > An example: > > body = DIV("this","is","the","body") > > Result: a DIV with four elements in it. > > body.append(["and","additional","elements"]) > > Result: Not what you wanted! It appends a list to the original DIV > making a mess. > > body.extend(["and","additional","elements"]) > > This is what you wanted: > > DIV("this","is","the","body","and","additional","elements") > > I've been monkey-patching "extend" into DIV quite awhile now and thought > you may want to consider adding it to the DIV helper. Here is my > monkey-patch: > > def extend(self,coll): > self._setnode(coll) > ret = self.components.extend(coll) > self._fixup() > return ret > DIV.extend = extend > > /dps -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.