# Tag: nested-lists

## How to create the set of all possible sets formed by selecting 0 or 1 elements from n lists

As an example, say I have the following six lists: I want to make a new list that has either 0 or 1 elements from each of these lists. One such list could be [2,2,4,1,2,1] which is made by selecting the first element from each list. Another such list could be [2,3,2,2,4] which is made by selecting the last element

## Remove duplicate value on nested list python

I have a problem here when I want to remove duplicate in a list that has a nested list, how can I remove the duplicate value from list? What I got here from my script, it can remove a duplicate, but the nested list has a different result from what I expect. This is my script: Result: Expected Result: Answer

## How to concatenate a list of sublists equally chunked

I have a list that contains sublists of two different types of items (for instance, cats and dogs). I also have a function chunk(list, n_sublists) that splits the list into n_sublists of equal size. Then, i’d like to create a final list that merges the chunked lists from each type. An example: I hope the example makes it clear. However,

## Method for mapping dictionary values in complex list

Inputs I have a very complicated list of list. And i have a dictionary that has each element of the list as a key. I’m going to map each element of the list to the value of the dictionary. output I tried the following to use the for loop as little as possible. I would appreciate it if you could

## Checking If Position Exists in Nested List

I’m trying to solve a Python coding problem. Given a certain array containing only 1’s and 0’s I must write a program that returns an array following a few rules: Each 1 must be replaced with a 9 …

## Trying to find unique subarrays and sub-elements?

I have an array will subarrays containing [page_name, url, and id] in dirty_pages. This array contain duplicate subarrays. I need to parse each subarray in dirty_pages into clean_pages such that: …

## select top 3 unique items in a list of list

I have a list of items and it outputs a list of list: item_list = [‘book’, ‘pen’] output = [ [‘pencil’, ‘eraser’, ‘pen’, ‘glue’, ‘folders’], [‘notepad’, ‘book’,’pencil’, ‘markers’,’ruler’,’…

## Finding index in nested list

I am trying to create a function that will take as input a nested list and an item, and return a list of indices. For example list = [0, 5, [6, 8, [7, 3, 6]], 9, 10] and item = 7 should return [2, 2, 0], since list[2][2][0] = 7 my code should work since […]

## Print list of lists in separate lines

I have a list of lists: a = [[1, 3, 4], [2, 5, 7]] I want the output in the following format: 1 3 4 2 5 7 I have tried it the following way , but the outputs are not in the desired way: for i in …

## Is it possible to index nested lists using tuples in python?

I just started with python and very soon wondered if indexing a nested list with a tuple was possible. Something like: elements[(1,1)] One example where I wanted to do that was something similar to the code below in which I save some positions of the matrix that I will later need to access in a tuple called index. It seems