Found a total of 10000 related content
Iterable - JavaScript Challenges
Article Introduction:You can find all the code in this post at the repo Github.
Iterable related challenges
Iterable
/**
* @param {any} data
* @return {object}
*/
function createCustomIterable(data) {
return {
[Symbol.iterator]()
2024-11-03
comment 0
1031
What are iterable pseudo-type in PHP 7.1?
Article Introduction:InPHP7.1,"iterable"isapseudo-typethatrepresentseitheranarrayoranobjectimplementingtheTraversableinterface.1.Itallowsfunctionstoacceptanyloopabledatastructure,enhancingflexibility.2.Developerscanuseitinparameterandreturntypedeclarations.3.It
2025-06-28
comment 0
752
Explaining Iterable vs Iterator in Python
Article Introduction:The aim of this page?is to demonstrate the dynamics of the 2 iteration protocols:
iterable
iterator
1. BUT FIRST (TO ADD TO CONFUSINGLY SIMILAR WORDS), LET'S ADDRESS ITERATION
iteration - of course - is taking items one by one from
2025-01-01
comment 0
981
How to make a python class iterable
Article Introduction:In order to make Python classes iterable, the \_\_iter\_\_ and \_\_next\_\_ methods need to be implemented. 1. Implement \_\_iter\_\_Return an iterator object (usually itself or new object); 2. Define the \_\_next\_\_ method in the iterator to control each return value and stop conditions; 3. The iterator can be classified separately to support multiple independent loops; 4. Pay attention to throwing StopIteration to avoid infinite loops and ensure that the state is managed correctly.
2025-07-03
comment 0
140
How to make a Python class iterable?
Article Introduction:In order to make instances of Python classes iterable, the __iter__ method needs to be implemented. There are three specific methods: 1. Implement __iter__ to return built-in iterators, such as returniter(self.items); 2. Customize the iterator class, implement the __iter__ and __next__ methods at the same time, and ensure that each call __iter__ returns a new instance to support multiple iterations; 3. Use generator functions to simplify the code, and use yield in __iter__ to automatically generate iteration logic. If you want the object to iterate multiple times, __iter__ must return a new iterator instead of itself.
2025-07-14
comment 0
774
How to make an object iterable in Python?
Article Introduction:In Python, to make an object iterable, you need to implement the __iter__ method and return an iterator with the __next__ method; the specific steps are as follows: 1. Define the __iter__ method in the class, and return itself or another iterator object that implements the __next__ method; 2. If you use the generator function to implement __iter__, you can automatically manage the state and iterative logic through the yield keyword; 3. Every time you call iter(), you should return a new iterator to ensure that multiple loops do not interfere with each other, and throw a StopIteration exception at the end of the iteration to prevent infinite loops.
2025-07-02
comment 0
709
zip in Python
Article Introduction:Buy Me a Coffee?
zip() can create an iterable by combining multiple iterables as shown below:
*Memos:
The iterable stops when the shortest input iterable is exhausted.
The iterable cannot be directly accessed with index so use list() to access i
2024-12-28
comment 0
884