# Desired behavior when calling \`shuffle\` or \`select\` on \`interleave\_datasets\`

**URL:** <https://discuss.huggingface.co/t/desired-behavior-when-calling-shuffle-or-select-on-interleave-datasets/8507>\
**Category:** 🤗Datasets\
**Created:** [July 20, 2021, 1:28am UTC](https://discuss.huggingface.co/t/desired-behavior-when-calling-shuffle-or-select-on-interleave-datasets/8507 "2021-07-20T01:28:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mralexis](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@mralexis](https://discuss.huggingface.co/u/mralexis)\
**Post date:** [July 20, 2021, 1:28am UTC](https://discuss.huggingface.co/t/desired-behavior-when-calling-shuffle-or-select-on-interleave-datasets/8507/1 "2021-07-20T01:28:49Z")

</div>

Could someone explain these operations on `interleave_datasets`? I didn’t find any word in the doc on this. Thanks.

---

<div class="post-metadata">

**Author:** ![lhoestq](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lhoestq/32/64813_2.png) [@lhoestq](https://discuss.huggingface.co/u/lhoestq)\
**Post date:** [July 20, 2021, 9:59am UTC](https://discuss.huggingface.co/t/desired-behavior-when-calling-shuffle-or-select-on-interleave-datasets/8507/2 "2021-07-20T09:59:25Z")

</div>

Hi ! You can find the documentation of `interleave_datasets` here:

> **[Main classes](https://huggingface.co/docs/datasets/package_reference/main_classes)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

Interleaving datasets can be seen as a way to alternate between examples of several datasets. For example

```python
from datasets import Dataset, interleave_datasets

d1, d2 = {"foo": ["a", "b", "c"]}, {"foo": ["x", "y", "z"]}
d1, d2 = Dataset.from_dict(d1), Dataset.from_dict(d2)
d3 = interleave_datasets([d1, d2])
print(d3["foo"])
# ['a', 'x', 'b', 'y', 'c', 'z']

```

You can call shuffle or select on the resulting dataset if you want.  
Shuffle will shuffle the order of the dataset:

```python
print(d3.shuffle(seed=42)["foo"])
['y', 'b', 'z', 'c', 'x', 'a']

```

Select will select the indices you want:

```python
print(d3.select([0, 1, 2])["foo"])
# ['a', 'x', 'b']

```
