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
54
votes
3 answers
how to convert pandas series to tuple of index and value
I'm looking for an efficient way to convert a series to a tuple of its index with its values.
s = pd.Series([1, 2, 3], ['a', 'b', 'c'])
I want an array, list, series, some iterable:
[(1, 'a'), (2, 'b'), (3, 'c')]

piRSquared
- 285,575
- 57
- 475
- 624
45
votes
2 answers
Why there is no getFirst(iterable) method?
Iterables present two methods for getLast
public static T getLast(Iterable iterable);
public static T getLast(Iterable iterable, @Nullable T defaultValue);
but only one for getFirst
public static T getFirst(Iterable…

Stan Kurilin
- 15,614
- 21
- 81
- 132
45
votes
5 answers
Java: why does Collection.addAll can not accept Iterables?
I wonder why the Collection.addAll() method only accepts other Collections but not Iterables. Why is that?
Any similar method to do that for Iterables?

Albert
- 65,406
- 61
- 242
- 386
44
votes
2 answers
iter() not working with datetime.now()
A simple snippet in Python 3.6.1:
import datetime
j = iter(datetime.datetime.now, None)
next(j)
returns:
Traceback (most recent call last):
File "", line 1, in
StopIteration
instead of printing out the classic now() behavior with…

Vidak
- 1,083
- 14
- 29
40
votes
6 answers
What is the Iterable interface used for?
I am a beginner and I cannot understand the real effect of the Iterable interface.

Johanna
- 27,036
- 42
- 89
- 117
39
votes
6 answers
Check if a variable type is iterable?
Is there any way to check if an arbitrary variable type is iterable?
So to check if it has indexed elements or I can actually loop over it's children? (Use foreach for example?)
Is it possible to create a universal template for that?
I've found…

Roy Nieterau
- 1,226
- 2
- 15
- 26
35
votes
2 answers
Make a Stream into an Iterable?
Stream inherits an iterator() method to produce an Iterator.
But I need an Iterable rather than an Iterator.
For example, given this string:
String input = "this\n" +
"that\n" +
"the_other";
…I need to pass those parts of string…

Basil Bourque
- 303,325
- 100
- 852
- 1,154
35
votes
4 answers
what's the point of having both Iterator.forEachRemaining() and Iterable.forEach()?
and both of them get a Consumer as parameter. so if Java 8, is meant to avoid confusions, like it has done in Time API, why has it added a new confusion? or am I missing some point?

mostafa.S
- 1,452
- 4
- 16
- 27
33
votes
5 answers
How can I make my class iterable so I can use foreach syntax?
I have Book and BookList classes. BookList is something like this:
public class BookList
{
private final List bList = new ArrayList();
public int size() { return bList.size(); }
public boolean isEmpty() { ... }
…

b4da
- 3,010
- 4
- 27
- 34
32
votes
3 answers
How to check if an object is iterable in Python?
How does one check if a Python object supports iteration, a.k.a an iterable object (see definition
Ideally I would like function similar to isiterable(p_object) returning True or False (modelled after isinstance(p_object, type)).

Boaz
- 25,331
- 21
- 69
- 77
32
votes
7 answers
Finding the Max value in a two dimensional Array
I'm trying to find an elegant way to find the max value in a two-dimensional array.
for example for this array:
[0, 0, 1, 0, 0, 1] [0, 1, 0, 2, 0, 0][0, 0, 2, 0, 0, 1][0, 1, 0, 3, 0, 0][0, 0, 0, 0, 4, 0]
I would like to extract the value '4'.
I…

Shuki
- 323
- 1
- 3
- 5
32
votes
3 answers
How to perform Stream functions on an Iterable?
In Java 8, the Stream class does not have any method to wrap a an Iterable.
Instead, I am obtaining the Spliterator from the Iterable and then obtaining a Stream from StreamSupport like this:
boolean parallel =…

The Coordinator
- 13,007
- 11
- 44
- 73
30
votes
2 answers
How do I make a class iterable?
This is my class
public class csWordSimilarity
{
public int irColumn1 = 0;
public int irColumn2 = 0;
public int irColumn3 = 0;
public int irColumn4 = 0;
public int irColumn5 = 0;
}
I want to make that class iterable to be used…

Furkan Gözükara
- 22,964
- 77
- 205
- 342
29
votes
7 answers
How to find the index of the nth time an item appears in a list?
Given:
x = ['w', 'e', 's', 's', 's', 'z','z', 's']
Each occurrence of s appears at the following indices:
1st: 2
2nd: 3
3rd: 4
4th: 7
If I do x.index('s') I will get the 1st index.
How do I get the index of the 4th s?

Rimoun
- 455
- 1
- 9
- 16
29
votes
2 answers
Printing the same character several times without a loop
I would like to "beautify" the output of one of my Dart scripts, like so:
-----------------------------------------
OpenPGP signing notes from key `CD42FF00`
-----------------------------------------
And I wonder if there is a…

Diti
- 1,454
- 3
- 23
- 38