iterator Questions
9
Solved
I have a generator function like the following:
def myfunct():
...
yield result
The usual way to call this function would be:
for r in myfunct():
dostuff(r)
My question, is there a way to ...
Fpc asked 19/1, 2011 at 21:55
17
Solved
In terms of performance, what would work faster? Is there a difference? Is it platform dependent?
//1. Using vector<string>::iterator:
vector<string> vs = GetVector();
for(vector<...
Espouse asked 22/4, 2009 at 10:55
2
Solved
I have a MongoDB table containing 500 documents:
db.x.find().count()
Now I'd like to iterate over the all entries. Unfortunately the following code only gives 49, instead of 500:
a=0; for (s in...
Adel asked 19/1, 2015 at 22:48
4
Solved
Given a list of pairs xys, the Python idiom to unzip it into two lists is:
xs, ys = zip(*xys)
If xys is an iterator, how can I unzip it into two iterators, without storing everything in memory?
...
Wizardly asked 12/6, 2015 at 14:3
4
Solved
It can be useful to iterate over multiple variables at once, overlapping (slice::windows), or not (slice::chunks).
This only works for slices; is it possible to do this for iterators, using tuples ...
20
Solved
Do Python iterators have a hasnext method?
7
Solved
How can I select a random element in an std::set?
I naively tried this:
int GetSample(const std::set<int>& s) {
double r = rand() % s.size();
return *(s.begin() + r); // compile erro...
4
Solved
I have a std::vector<std::string> m_vPaths; I iterate over this vector and call ::DeleteFile(strPath) as I go. If I successfully delete the file, I remove it from the vector.
My questio...
Erhart asked 22/10, 2009 at 1:37
2
Solved
I have the following code:
import torch
import numpy as np
import pandas as pd
from torch.utils.data import TensorDataset, DataLoader
# Load dataset
df = pd.read_csv(r'../iris.csv')
# Extract fea...
Probationer asked 24/6, 2020 at 7:34
4
Solved
Lets say I have a small integer array like this:
{10,20,30}
Now for the items of that array I want to apply the following formula:
10^(arrayLenght-1) + 20^{arrayLenght-2) + 30^{arrayLenght-3}
...
4
Solved
Let's say I have an iterator:
function* someIterator () {
yield 1;
yield 2;
yield 3;
}
let iter = someIterator();
... that I look at the next element to be iterated:
let next = iter.next()...
Axis asked 11/4, 2020 at 21:58
19
Solved
I would like to get the first item from a list matching a condition. It's important that the resulting method not process the entire list, which could be quite large. For example, the following fun...
5
Solved
I'm trying to create a map inside a map:
typedef map<float,mytype> inner_map;
typedef map<float,inner_map> outer_map;
Will I be able to put something inside inner map, or does iterat...
11
Solved
11
There are multiple ways of finding out the last iteration of a for and for...in loop. But how do I find the last iteration in a for...of loop. I could not find that in the documentation.
for (item ...
Britten asked 9/1, 2019 at 19:10
12
C++11 provides multiple ways to iterate over containers. For example:
Range-based loop
for(auto c : container) fun(c)
std::for_each
for_each(container.begin(),container.end(),fun)
However wh...
Eddington asked 23/9, 2012 at 12:13
2
Solved
I'm trying to figure out what is the cost of cloning iterators that originate from into_iter() in Rust, but can't find anything meaningful.
Consider the code like this:
let v = vec![1,2,3,4,...]; /...
1
Solved
Let's say we have the following nested loop:
MyClass myobject;
for (const std::array<int,16>& arr : myobject)
{
for (int i : arr) { /* do something with i */ }
}
where MyClass can iter...
Promptbook asked 18/10, 2023 at 16:48
3
Solved
We are using a library by another vendor, which apparently was compiled with the wrong flags, namely _ITERATOR_DEBUG_LEVEL = 0 in 32bit-Debug-mode. While I have already filed a bug report with them...
Rubie asked 20/4, 2011 at 8:56
2
Solved
I'm implementing an iterator that iterates over the results of a generator function rather than over a data structure in memory such as a vector or map.
Reading through the final working draft for...
Smug asked 8/10, 2017 at 1:52
2
Solved
In PHP 7.1 there is a new iterable psudo-type which abstracts arrays and Traversable objects.
Suppose that in my code I have a class like the following:
class Foo
{
private $iterable;
public f...
25
Solved
Many times I need to do things TWICE in a for loop. Simply I can set up a for loop with an iterator and go through it twice:
for (i = 0; i < 2; i++)
{
// Do stuff
}
Now I am interested in do...
15
Solved
I'm trying to write the Haskell function 'splitEvery' in Python. Here is it's definition:
splitEvery :: Int -> [e] -> [[e]]
@'splitEvery' n@ splits a list into length-n pieces. The last
pie...
5
How do I convert an Iterator<&str> to a String, interspersed with a constant string such as "\n"?
For instance, given:
let xs = vec!["first", "second", "...
1
I have a parallel code that can be reduced to basically:
#include <algorithm>
#include <vector>
struct TKeyObjPtr;
class TObj
{
public:
virtual void Calculate(TKeyObjPtr const &...
Keary asked 4/2, 2019 at 18:16
© 2022 - 2025 — McMap. All rights reserved.