velocity: do something except in last loop iteration
You can use a test if you are in last iteration:: #foreach( $item in $list ) $item.text #if( $foreach.hasNext ), #end #end
You can use a test if you are in last iteration:: #foreach( $item in $list ) $item.text #if( $foreach.hasNext ), #end #end
The .find(‘selector’) method is basically a recusive version of .children(), and will find any descendant object that matched the selector, as opposed to .children() which only finds objects in the first level of descendants. 2nd EDIT (I phrased badly the first time, and messed up the code a bit!): Ok, I don’t think this functionality … Read more
The type of each element of a tuple can be different, so you can’t iterate over them. Tuples are not even guaranteed to store their data in the same order as the type definition, so they wouldn’t be good candidates for efficient iteration, even if you were to implement Iterator for them yourself. However, an … Read more
It’s located here in the docs: One method needs to be defined for container objects to provide iteration support: container.__iter__() Return an iterator object. The object is required to support the iterator protocol described below. If a container supports different types of iteration, additional methods can be provided to specifically request iterators for those iteration … Read more
From top left to bottom right var theArray = [“ABCD”,”EFGH”,”IJKL”]; var length = { “x” : theArray[0].length, “y” : theArray.length }; length.max = Math.max(length.x, length.y); var temp, k, x, y; for (k = 0; k <= 2 * (length.max – 1); ++k) { for (temp = [], y = length.y – 1; (x = k … Read more
My personal preference: just keep the extra index. It’s clear as it is, and in case you ever have an if() inside the loop, you can also easily skip the count: std::list<std::string> items; { int i = 0; for (auto & item : items) { if (some_condition(item)) { item += std::to_string(i); // mark item as … Read more
This can be done with itertools.chain: import itertools l1 = [1, 2, 3, 4] l2 = [5, 6, 7, 8] for i in itertools.chain(l1, l2): print(i, end=” “) Which will print: 1 2 3 4 5 6 7 8 As per the documentation, chain does the following: Make an iterator that returns elements from the … Read more
listOfStuff =([a,b], [c,d], [e,f], [f,g]) for item in listOfStuff[1:3]: print item You have to iterate over a slice of your tuple. The 1 is the first element you need and 3 (actually 2+1) is the first element you don’t need. Elements in a list are numerated from 0: listOfStuff =([a,b], [c,d], [e,f], [f,g]) 0 1 … Read more
You could do something like this: <li *ngFor=”let o of obj”> <p *ngFor=”let objArrayElement of generateArray(o)”> {{objArrayElement}} </p> </li> where generateArray looks like: generateArray(obj){ return Object.keys(obj).map((key)=>{ return obj[key]}); }