Question: I am working on a project where we frequently work with a list of usernames. We also have a function to take a username and return a dataframe with that user's data. E.g.

```
users = c("bob", "john", "michael")

get_data_for_user = function(user)
{
  data.frame(user=user, data=sample(10))
}

```

We often:

1. Iterate over each element of `users`
2. Call `get_data_for_user` to get their data
3. `rbind` the results into a single dataerame

I am currently doing this in a purely imperative way:

```
ret = get_data_for_user(users[1])
for (i in 2:length(users))
{
  ret = rbind(ret, get_data_for_user(users[i]))
}

```

This works, but my impression is that all the cool kids are now using libraries like `purrr` to do this in a single line. I am fairly new to `purrr`, and the closest I can see is using `map_df` to convert the vector of usernames to a vector of dataframes. I.e.

```
dfs = map_df(users, get_data_for_user)

```

That is, it seems like I would still be on the hook for writing a loop to do the `rbind`.

I'd like to clarify whether my solution (which works) is currently considered best practice in R / amongst users of the tidyverse.

Thanks.

Answer: 
You can use this:

```
s_index=df.index.to_series()
l = s_index.groupby(s_index.diff().ne(1).cumsum()).agg(list).to_numpy()

```

Output:

```
l[0]
[45, 46, 47]

```

and

```
l[1]
[51, 52]

```
The issue is with this line

```
sequences[seq] = [index]

```

You are trying to assign the list an index which is not created. Instead do this.

```
sequences.append([index])

```