What exactly are iterator, iterable, and iteration?

What is the most basic definition of “iterable”, “iterator” and “iteration” in Python? I have read multiple definitions but I am unable to identify the exact meaning as it still won’t sink in. Can someone please help me with the 3 definitions in layman terms? 18 s 18 Iteration is a general term for taking … Read more

How to remove items from a list while iterating?

This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. 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 use in … Read more

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 not always. Here’s some specific code: public static void main(String[] args) { Collection<Integer> l = new ArrayList<>(); for (int i = 0; i < 10; ++i) … Read more