nested-lists

How to names lists under list when using lapply?

故事扮演 提交于 2021-01-27 21:57:42
问题 I have a two nested loop which I want to do it with lapply instead of for loops. I have made up the following simple example: a<-as.list(c(1,2)) b<-as.list(c(6,7)) results<-lapply(a, function(x) lapply(b, function(y) x+y)) > results [[1]] [[1]][[1]] [1] 7 [[1]][[2]] [1] 8 [[2]] [[2]][[1]] [1] 8 [[2]][[2]] [1] 9 how can I assign names to this list, I can assign names to the first level using names(result)<-a, but I do not know how to do it for the second level. And naming should be done in

Python: Removing a single element from a nested list

两盒软妹~` 提交于 2021-01-27 06:34:35
问题 I'm having trouble figuring out how to remove something from within a nested list. For example, how would I remove 'x' from the below list? lst = [['x',6,5,4],[4,5,6]] I tried del lst[0][0] , but I get the following result: TypeError: 'str' object doesn't support item deletion. I also tried a for loop, but got the same error: for char in lst: del char[0] 回答1: Your code works fine. Are you sure lst is defined as [['x',6,5,4],[4,5,6]] ? Because if it is, del lst[0][0] effectively deletes 'x' .

How do I return the values of a nested structure with a list of maps in Flutter

我们两清 提交于 2021-01-02 03:52:16
问题 Still trying to learn maps and lists. My goal is to return a list from a nested list of maps. The function getMovements() works as expected. It renders a list of movements. Then I try to create another function getVariationsByMovement() which passes in the movement string name to attempt to return a list of variationNames. In my UI, I present a list of movements. The user selects a movements and the next page renders with a list of variations. I am stuck in the function below

How do I return the values of a nested structure with a list of maps in Flutter

こ雲淡風輕ζ 提交于 2021-01-02 03:50:52
问题 Still trying to learn maps and lists. My goal is to return a list from a nested list of maps. The function getMovements() works as expected. It renders a list of movements. Then I try to create another function getVariationsByMovement() which passes in the movement string name to attempt to return a list of variationNames. In my UI, I present a list of movements. The user selects a movements and the next page renders with a list of variations. I am stuck in the function below

R (purrr) flatten list of named lists to list and keep names

妖精的绣舞 提交于 2020-12-26 07:39:27
问题 Maybe I'm missing something obvious but trying to flatten a list of named lists of named lists in R (may even be more nested) into eventually one flat list. purrr and rlist seem to have tools for that. How can I achieve that names of sublists become name precrypts of flattened result list, e.g. list1.blist.a in purrr ? My actual list is more deeply nested with varying number of levels and repeating names on different levels. In the end I perform purrr::map_df(final_list, bind_rows) and this