All Questions

624
votes
18answers
279945 views

Remove items from a list while iterating

I'm iterating over a list of tuples in Python, and am attempting to remove them if they meet certain criteria. for tup in somelist: if determine(tup): code_to_remove_tup What should I...
3467
votes
23answers
3095397 views

For-each over an array in JavaScript?

How can I loop through all the entries in an array using JavaScript? I thought it was something like this: forEach(instance in theArray) Where theArray is my array, but this seems to be incorrect....
2228
votes
35answers
1768536 views

How to efficiently iterate over each Entry in a 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 e...
1490
votes
7answers
306894 views

How does PHP 'foreach' actually work?

Let me prefix this by saying that I know what foreach is, does and how to use it. This question concerns how it works under the bonnet, and I don't want any answers along the lines of "this is how you...
2620
votes
7answers
2863210 views

Iterate through a HashMap

Possible Duplicate: How do I iterate over each Entry in a Collection Map? What's the best way to iterate over the items in a HashMap?
241
votes
8answers
164188 views

What exactly are Python's iterator, iterable, and iteration protocols?

What are the most basic definitions of "iterable", "iterator" and "iteration" in Python? I've read multiple definitions but their exact meaning still won't sink in. Can someone please help me with t...
262
votes
18answers
87228 views

Way to go from recursion to iteration

I've used recursion quite a lot on 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 very ...
149
votes
18answers
52106 views

Can every recursion be converted into iteration?

A reddit thread brought up an apparently interesting question: Tail recursive functions can trivially be converted into iterative functions. Other ones, can be transformed by using an explicit sta...
381
votes
10answers
590462 views

Ways to iterate over a List in java?

Being somewhat new to the Java language I'm trying to familiarize myself with all the ways (or at least the non-pathological ones) that one might iterate through a list (or perhaps other collections) ...
338
votes
11answers
172055 views

How do I use Python's itertools.groupby()?

I haven't been able to find an understandable explanation of how to actually use Python's itertools.groupby() function. What I'm trying to do is this: Take a list - in this case, the children of an...

Previous Next