iterator Questions

3

I have a 34 GB json file that has many data inside. I tried to import into my mongodb by using mongoimport --file file.json - but it failed ofcourse the file is too big and threw a memory system th...
Castroprauxel asked 15/10, 2014 at 22:31

3

Solved

In a defined object some values are kept in a dict, and I want to iterate over the contents in that dict as when referring to a plain dict, thus with directly access using [], and loop using e.g. ....
Reposit asked 13/3, 2015 at 13:18

3

Imagine we have an iterator, say iter(range(1, 1000)). And we have two functions, each accepting an iterator as the only parameter, say sum() and max(). In SQL world we would call them aggregate fu...
Mundane asked 26/4, 2018 at 9:16

3

Solved

I m new to Java Collections and my doubt is why can't i traverse a element in linkedlist in backward directions.Below I'll explain what i did and please clarify my doubts. I've created interface ...
Americaamerican asked 13/9, 2015 at 5:26

8

Solved

I'm using a foreach loop to go through the REQUEST array, as I want to have an easy way to utilize the REQUEST array's keys and values. However, I also want to have a numerical index of how many t...
Harneen asked 13/8, 2012 at 14:36

13

Assume I have the following code: vector<int> list; for(auto& elem:list) { int i = elem; } Can I find the position of elem in the vector without maintaining a separate iterator?
Hubey asked 9/6, 2012 at 15:37

1

I'm quite new with Rust, and my first 'serious' project has involved writing a Python wrapper for a small Rust library using PyO3. This has mostly been quite painless, but I'm struggling to work ou...
Scotfree asked 22/5, 2020 at 12:37

4

Solved

In C#, with LINQ, if I have en enumeration enumerable, I can do: // a: Does the enumerable contain an item that satisfies the lambda? bool contains = enumerable.Any(lambda); // b: How many items s...

2

Solved

Consider the following dummy example: def common_divisors_generator(n, m): # Init code factors_n = [i for i in range(1, n + 1) if n%i == 0] factors_m = [i for i in range(1, m + 1) if m%i == 0]...
Hereld asked 18/7, 2018 at 8:35

1

Solved

Even though I have declare the type for the iterator i as NumericalString, TypeScript still throws this error: Argument of type 'string' is not assignable to parameter of type 'type'.deno-ts(2345)...
Niels asked 28/7, 2023 at 7:10

3

Solved

I've created a function that generates a list of alphabets incrementing continuously. A, B, C ..., Z. After Z, it goes to AA, AB, AC ...AZ. This pattern repeats. This is similar to MS Excel's colum...
Andreeandrei asked 7/2, 2017 at 20:25

16

Solved

Can you think of a nice way (maybe with itertools) to split an iterator into chunks of given size? Therefore l=[1,2,3,4,5,6,7] with chunks(l,3) becomes an iterator [1,2,3], [4,5,6], [7] I can thi...
Gretagretal asked 24/1, 2012 at 17:44

9

Solved

In many languages we can do something like: for (int i = 0; i < value; i++) { if (condition) { i += 10; } } How can I do the same in Python? The following (of course) does not work: for ...
Worldshaking asked 1/4, 2011 at 4:54

3

I have a test case in which in the setUp, I create an object for which I want to mock the function uuid4 in the module uuid. TEST_UUIDS = ['uuid_{}'.format(i) for i in range(10000)] UUID_POOL = i...
Loidaloin asked 6/6, 2017 at 16:56

5

I am building an Array with const myCanvas = document.getElementsByTagName('canvas') that it's actually working. It returns me something like this: images: [ 0: canvas, 1: canvas, 2: canvas ] T...
Cleopatracleopatre asked 23/8, 2019 at 6:45

2

Solved

In an algorithm, I can determine the value_type directly from the iterator via iter::value_type. Why do algorithms use iterator_traits to do the same? #include <iostream> #include <v...
Weinstock asked 14/6, 2023 at 8:1

8

Solved

In Ruby, instead of repeating the "require" (the "import" in Python) word lots of times, I do %w{lib1 lib2 lib3 lib4 lib5}.each { |x| require x } So it iterates over the set of...
Fregger asked 15/7, 2010 at 22:28

13

Solved

Is there any way to check if an iterator (whether it is from a vector, a list, a deque...) is (still) dereferenceable, i.e. has not been invalidated? I have been using try-catch, but is there a mor...
Concur asked 14/1, 2010 at 8:30

8

Solved

Suppose I have an arbitrary iterable - for example, a generator that iterates over lines of a file and yields the ones matching a regex. How can I count the number of items in that iterable, suppos...
Unused asked 21/3, 2011 at 22:35

6

Solved

I'm trying to access the previously iterated element in a loop going through all the elements of a list. To be more specific, my loop looks like this: for (iter=list_object.begin(); iter!= list_o...
Coleencolella asked 7/4, 2011 at 19:17

7

Solved

Say you want to iterate over a sequence [0 to n] in a random order, visiting every element exactly once. Is there any way to do this in O(1) memory, i.e. without creating an [1..n] sequence with st...
Donoho asked 17/9, 2012 at 13:41

8

Solved

I've implemented a custom java.util.Iterator using a resource that should be released at the end using a close() method. That resource could be a java.sql.ResultSet, a java.io.InputStream etc... p...
Camey asked 15/7, 2010 at 16:56

1

Solved

C++11 changed std::vector::erase to take a const_iterator instead of an iterator. The same thing applies to std::deque and std::list, while std::forward_list came in C++11 with erase_after, which a...
Meurer asked 29/4, 2023 at 12:28

12

Solved

I want to have a reversed list view on a list (in a similar way than List#sublist provides a sublist view on a list). Is there some function which provides this functionality? I don't want to make...
Hierodule asked 18/10, 2010 at 19:45

15

Solved

I'm trying to iterate over a typescript map but I keep getting errors and I could not find any solution yet for such a trivial problem. My code is: myMap : Map<string, boolean>; for(let key...
Extremist asked 8/6, 2016 at 10:1

© 2022 - 2025 — McMap. All rights reserved.