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: 
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])

```
I use the diff to find when the index value diff changes greater than 1. I iterate the tuples and access by index their values.

```
index=[45,46,47,51,52]
price=[3909.0,3908.75,3908.50,3907.75,3907.5]
count=[8,8,8,8,8]

df=pd.DataFrame({'index':index,'price':price,'count':count})
df['diff']=df['index'].diff().fillna(0)
print(df)
result_list=[[]]
seq=0
for row in df.itertuples():
     index=row[1]
     diff=row[4]
     if diff<=1:
         result_list[seq].append(index)
     else:
         seq+=1
         result_list.insert(1,[index])

print(result_list)  

output:
[[45, 46, 47], [51, 52]]

```