Questions tagged [iteration]
Iterations are the successive repetitions in loops such as for, foreach or while. Questions with this tag are often concerned about how to best handle a collection of data.
iteration
10,911
questions
43
votes
5
answers
25k
views
Converting a list of tuples into a dict
I have a list of tuples like this:
[
('a', 1),
('a', 2),
('a', 3),
('b', 1),
('b', 2),
('c', 1),
]
I want to iterate through this keying by the first item, so, for example, I could print something ...
6
votes
7
answers
12k
views
iterative version of recursive algorithm to make a binary tree
Given this algorithm, I would like to know if there exists an iterative version. Also, I want to know if the iterative version can be faster.
This some kind of pseudo-python...
the algorithm returns ...
55
votes
3
answers
16k
views
Why is it bad to use an iteration variable in a lambda expression
I was just writing some quick code and noticed this complier error
Using the iteration variable in a lambda expression may have unexpected results.
Instead, create a local variable within the ...
1301
votes
31
answers
524k
views
Iterating through a Collection, avoiding ConcurrentModificationException when removing objects in a loop
We all know you can't do the following because of ConcurrentModificationException:
for (Object i : l) {
if (condition(i)) {
l.remove(i);
}
}
But this apparently works sometimes, but ...
485
votes
17
answers
707k
views
What is the easiest/best/most correct way to iterate through the characters of a string in Java?
Some ways to iterate through the characters of a string in Java are:
Using StringTokenizer?
Converting the String to a char[] and iterating over that.
What is the easiest/best/most correct way to ...
13
votes
13
answers
6k
views
Is Iterator initialization inside for loop considered bad style, and why?
Typically you will find STL code like this:
for (SomeClass::SomeContainer::iterator Iter = m_SomeMemberContainerVar.begin(); Iter != m_SomeMemberContainerVar.end(); ++Iter)
{
}
But we actually have ...
0
votes
6
answers
17k
views
.NET Fastest way to iterate through rows in a datatable?
Which is generally fastest when reading/comparing row info from a DataTable?
'assume dt as datatable'
'method 1'
dim i as int32
for i = 0 to dt.rows.count - 1
....
next
'method 2'
dim row as ...
453
votes
21
answers
201k
views
Way to go from recursion to iteration
I've used recursion quite a lot during my many years of programming to solve simple problems, but I'm fully aware that sometimes you need iteration due to memory/speed problems.
So, sometime in the ...
3
votes
6
answers
2k
views
Team size and project iteration length [closed]
Do you think that project iteration length is related to project team size? If so, how? What other key factors do you use to recognize correct iteration length for different projects?
1
vote
4
answers
892
views
Is it correct to use the backtick / comma idiom inside a (loop ...)?
I have some code which collects points (consed integers) from a loop which looks something like this:
(loop
for x from 1 to 100
for y from 100 downto 1
collect `(,x . ,y))
My ...
13
votes
4
answers
3k
views
Is there a zip-like method in .Net?
In Python there is a really neat function called zip which can be used to iterate through two lists at the same time:
list1 = [1, 2, 3]
list2 = ["a", "b", "c"]
for v1, v2 in zip(list1, list2):
...
5
votes
4
answers
5k
views
How do I iterate a .Net IList collection in the reverse order?
I have an IList that contains items ( parent first ), they need to be added to a Diagram Document in the reverse order so that the parent is added last, drawn on top so that it is the first thing to ...
17
votes
14
answers
20k
views
In C# .NET 2.0, what's an easy way to do a foreach in reverse?
Lets say I have a Dictionary object:
Dictionary myDictionary<int, SomeObject> = new Dictionary<string, SomeObject>();
Now I want to iterate through the dictionary in reverse order. I can'...
34
votes
9
answers
14k
views
Iterators in C++ (stl) vs Java, is there a conceptual difference?
I'm returning to c++ after being away for a bit and trying to dust off the old melon.
In Java Iterator is an interface to a container having methods: hasNext(), next() and remove(). The presence of ...
3989
votes
46
answers
3.4m
views
How do I efficiently iterate over each entry in a Java Map?
If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map?
Will the ordering of ...