I am struggling with sublists, I would like to get items from list at indexes given in index_list where these indexes are also in sublist. I would like to also keep the structure. What is the best method to do that? Should I use zip()?
list = [['a','b','c'],['a','b','c','d'],['a','b','c']]
index_list = [[0,2],[1,2,3],[1,2]]
For each sublist, then for each index get the corresponding value (also don't use list
built-in name as variable name)
results = [[values[sub_idx][item] for item in sublist] for sub_idx, sublist in enumerate(index_list)]
CODE DEMO
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.