ValueError: max() arg is an empty sequence
Pass a default value which can be returned by max if the sequence is empty: max(v, default=0)
Pass a default value which can be returned by max if the sequence is empty: max(v, default=0)
The Standard is your friend, see [stmt.ranged]/1 For a range-based for statement of the form for ( for-range-declaration : expression ) statement let range-init be equivalent to the expression surrounded by parentheses ( expression ) and for a range-based for statement of the form for ( for-range-declaration : braced-init-list ) statement let range-init be equivalent … Read more
Error messages usually mean precisely what they say. So they must be read very carefully. When you do that, you’ll see that this one is not actually complaining, as you seem to have assumed, about what sort of object your list contains, but rather about what sort of object it is. It’s not saying it … Read more
A do..while can more directly be emulated in Go with a for loop using a bool loop variable seeded with true. for ok := true; ok; ok = EXPR { } is more or less directly equivalent to do { } while(EXPR) So in your case: var input int for ok := true; ok; ok … Read more
Here’s an example of iterating backward through a std::map: #include <iostream> #include <map> #include <string> int main() { std::map<std::string, std::string> m; m[“a”] = “1”; m[“b”] = “2”; m[“c”] = “3”; for (auto iter = m.rbegin(); iter != m.rend(); ++iter) { std::cout << iter->first << “: ” << iter->second << std::endl; } } If you are … Read more
I’m not clear why you can’t use the product of the bounds and do for x in range(y exp n) where n is the # of loops…. You say y exp n will be huge, but I’m sure python can handle it. However, that being said, what about some sort of recursive algorithm? def loop_rec(y, … Read more
You should use a C-style for loop to accomplish this: for ((i=1; i<=$1; i++)); do echo $i done This avoids external commands and nasty eval statements.
While the solution making use of filter is a fine solution and it’s more Swift-ly, there is another way, if making use of for-in is, nonetheless, still desired: func removeBelow(value: Int) { var results = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] for i in (0 ..< results.count).reversed() { if (results[i] < … Read more
In Swift 2, new where syntax was added: for value in boolArray where value == true { … } In Pre 2.0 one solution would be to call .filter on the array before you iterate it: for value in boolArray.filter({ $0 == true }) { doSomething() }
Here’s a solution using reduce. Split the time into a date string, and then set a key for each date. If the key exists push it onto the array: Update added the array format version const data = [ {notes: ‘Game was played’, time: ‘2017-10-04T20:24:30+00:00’, sport: ‘hockey’, owner: ‘steve’, players: ’10’, game_id: 1}, { notes: … Read more