An iterable is an object, such as a string or collection, that can be iterated over, yielding up its members one at a time.
Questions tagged [iterable]
1303 questions
28
votes
3 answers
How to make a custom object iterable?
I have a list of custom-class objects (sample is below).
Using: list(itertools.chain.from_iterable(myBigList)) I wanted to "merge" all of the stations sublists into one big list. So I thought I need to make my custom class an iterable.
Here is a…

Matthieu Riegler
- 31,918
- 20
- 95
- 134
26
votes
2 answers
Python threading error - must be an iterable, not int
I'm trying to calculate rolling r-squared of regression among first column and other columns in a dataframe (first column and second, first column and third etc.) But when I try threading, it kept telling me the error that
TypeError:…

Catherine Zhang
- 315
- 1
- 5
- 8
26
votes
1 answer
"yield from iterable" vs "return iter(iterable)"
When wrapping an (internal) iterator one often has to reroute the __iter__ method to the underlying iterable. Consider the following example:
class FancyNewClass(collections.Iterable):
def __init__(self):
self._internal_iterable =…

PeterE
- 5,715
- 5
- 29
- 51
26
votes
7 answers
Initializing a Set with an Iterable
I want to initialize a Set Implementation (HashSet) in Java with an Iterable. However, the constructor of HashSet doesn't accept Iterables, but only Collections type objects.
Is there a way to convert from Iterable to some subtype of Collections.

VaidAbhishek
- 5,895
- 7
- 43
- 59
24
votes
6 answers
Are there any Java standard classes that implement Iterable without implementing Collection?
I have a conundrum that's caused me to ponder whether there are any standard java classes that implement Iterable without also implementing Collection. I'm implementing one interface that requires me to define a method that accepts an…

Patrick M
- 10,547
- 9
- 68
- 101
23
votes
1 answer
Dart convert every element of list
I have a List stringValues; that are actually numbers in quotes. I want to convert this list to List intValues. What's an elegant way to do this?
There is list.forEach() that does not return anything, there is iterable.expand() that…

Gazihan Alankus
- 11,256
- 7
- 46
- 57
23
votes
5 answers
Is file object in python an iterable
I have a file "test.txt":
this is 1st line
this is 2nd line
this is 3rd line
the following code
lines = open("test.txt", 'r')
for line in lines:
print "loop 1:"+line
for line in lines:
print "loop 2:"+line
only prints:
loop 1:this is 1st…

Shengjie
- 12,336
- 29
- 98
- 139
22
votes
6 answers
Java: why can't iterate over an iterator?
I read Why is Java's Iterator not an Iterable? and Why aren't Enumerations Iterable?, but I still don't understand why this:
void foo(Iterator it) {
for (X x : it) {
bar(x);
baz(x);
}
}
was not made possible. In other words, unless…

noamtm
- 12,435
- 15
- 71
- 107
21
votes
4 answers
Is an iterator also an iterable?
I found that:
>>> a={'x':42, 'y':3.14, 'z':7}
>>> b=a.__iter__()
>>> b.__dir__()
['__next__', ..., '__iter__', ...]
>>> b
Does an iterator always have the __iter__ method?
According to…
user3284469
20
votes
7 answers
error TS2304: Build:Cannot find name 'Iterable' after upgrading to Angular 4
I am using Typescript 2.4.1 and have upgraded many packages in my project. Among them I upgraded Angular from 2 to 4.3.1.
After many corrections in @types packages, the errors I am left with are:
\node_modules\@types\jquery\index.d.ts(2955,63):…

Oliver H.
- 321
- 1
- 2
- 7
19
votes
2 answers
Filtering lists of generic types
Lists or Iterables can be filtered easily using guavas filter(Iterable> unfiltered, Class type). This operation performs two tasks: the list is filtered and transformed into a sequence of the given type T.
Quite often however I end up with…

Ditz
- 735
- 7
- 17
19
votes
1 answer
Star * operator on left vs right side of an assignment statement
This questions stems from PEP 448 -- Additional Unpacking Generalizations and is present in Python 3.5 as far as I'm aware (and not back-ported to 2.x). Specifically, in the section Disadvantages, the following is noted:
Whilst *elements, =…

Dimitris Fasarakis Hilliard
- 150,925
- 31
- 268
- 253
18
votes
3 answers
"Can only join an iterable" python error
I've already looked at this post about iterable python errors:
"Can only iterable" Python error
But that was about the error "cannot assign an iterable". My question is why is python telling me:
"list.py", line 6, in
reversedlist = '…

Derek
- 301
- 2
- 3
- 7
18
votes
4 answers
Python: map in place
I was wondering if there is a way to run map on something. The way map works is it takes an iterable and applies a function to each item in that iterable producing a list. Is there a way to have map modify the iterable object itself?

johannix
- 29,188
- 15
- 39
- 42
17
votes
3 answers
In JavaScript ES6, what is the difference between an iterable and iterator?
Is an iterable the same as an iterator, or are they different?
It seems, from the specifications, an iterable is an object, say, obj, such that obj[Symbol.iterator] refers to a function, so that when invoked, returns an object that has a next method…

nonopolarity
- 146,324
- 131
- 460
- 740