About 3,020,000 results
Open links in new tab
  1. python - What are iterator, iterable, and iteration? - Stack Overflow

    So an iterable is an object that you can get an iterator from. An iterator is an object with a next (Python 2) or __next__ (Python 3) method. Whenever you use a for loop, or map, or a list comprehension, …

  2. python - How to build a basic iterator? - Stack Overflow

    Iterator objects in python conform to the iterator protocol, which basically means they provide two methods: __iter__() and __next__(). The __iter__ returns the iterator object and is implicitly called at …

  3. Python: how to determine if an object is iterable?

    When you use for item in o for some iterable object o, Python calls iter(o) and expects an iterator object as the return value. An iterator is any object which implements a __next__ (or next in Python 2) …

  4. python - Iterating over a dictionary using a 'for' loop, getting keys ...

    Mar 16, 2017 · The way Python iterates is, in a context where it needs to, it calls the __iter__ method of the object (in this case the dictionary) which returns an iterator (in this case, a keyiterator object):

  5. python - How does __iter__ work? - Stack Overflow

    Oct 22, 2009 · In Python 2.6 and higher, the best way to implement an iterator is generally to use the appropriate abstract base class from the collections standard library module -- in Python 2.6, the …

  6. Python for loop and iterator behavior - Stack Overflow

    Apr 2, 2015 · The iter function is applied to the object to get an iterator (by the way: don't use iter as a variable name in Python, as you have done - it is one of the keywords).

  7. Python list iterator behavior and next(iterator) - Stack Overflow

    May 29, 2013 · It doesn't. The loop prints all of the items in the list, without skipping any. My first thought was that this might happen because the loop calls iter on what it is passed, and this might give an …

  8. python - How can I iterate over rows in a Pandas DataFrame? - Stack ...

    Mar 19, 2019 · To get high-precision timestamps in Python, see my answer here: High-precision clock in Python. How to iterate over Pandas DataFrame s without iterating After several weeks of working on …

  9. python - How can I iterate over files in a given directory? - Stack ...

    Apr 30, 2012 · I need to iterate through all .asm files inside a given directory and do some actions on them. How can this be done in a efficient way?

  10. python - How can I create a list of elements from an iterator (convert ...

    Mar 19, 2019 · Given an iterator user_iterator, how can I iterate over the iterator a list of the yielded objects? I have this code, which seems to work: user_list = [user for user in user_iterator] But is there