是否有等效itertools.chain
于 Java 的 python(带有或不带有第三方库)?
itertools.chain([1, 2, 3], [4, 5, 6]) # -> [1, 2, 3, 4, 5, 6]
像这样的东西:
new Iterable<E> {
public Iterator<E> iterator() {
return new Iterator<E>() {
Iterator<E> i1 = list1.iterator();
Iterator<E> i2 = list2.iterator();
public boolean hasNext() {
return i1.hasNext() || i2.hasNext();
}
public E next() {
if(i1.hasNext()) {
return i1.next();
} else if(i2.hasNext()) {
return i2.next();
} else {
throw new NoSuchElementException("Lists exhausted");
}
}
public void remove() {
throw new UnsupportedOperationException("...");
}
}
}
}