nested-lists

How to sort liberally-deep list of lists and integers?

How to sort liberally-deep list of lists and integers? Question: Let’s say I have a list like that: [[5, [2, 1], 3], [3, [8, 7], [2, 1, 3], 2], [[3, 2, 1], 3, -1]] (each list can store unspecified number of integers and lists in any order). Rules for sorting: integers (if any) should be …

Total answers: 2

Recursion on nested list

Recursion on nested list Question: I am trying to use recursion on a nested list. Here I am trying to get the innermost element. input_list = [1,2,3,4,[5,6,7,[8,9,[10]]]] list1 = input_list def sublist1(list, sublist=[]): if len(list) == 0: return sublist else: sublist.append(list) sublist1(list[1:], sublist) print(sublist) sublist1(list1) The output I am getting is this: [[1, 2, 3, …

Total answers: 3

How to access item in a nested list of dictionaries python?

How to access item in a nested list of dictionaries python? Question: I have the following format saved to a variable: [[{‘start’: 88608, ‘end’: 94176}], [{‘start’: 56352, ‘end’: 63456}, {‘start’: 119328, ‘end’: 151008}], [{‘start’: 88608, ‘end’: 114144}, {‘start’: 123936, ‘end’: 131040}, {‘start’: 136224, ‘end’: 160000}], [{‘start’: 79392, ‘end’: 144864}], [{‘start’: 110112, ‘end’: 147936}]] How would …

Total answers: 2

How to transform a csv file into a multi-dimensional list using Python?

How to transform a csv file into a multi-dimensional list using Python? Question: I started out with a 4d list, something like tokens = [[[["a"], ["b"], ["c"]], [["d"]]], [[["e"], ["f"], ["g"]],[["h"], ["i"], ["j"], ["k"], ["l"]]]] So I converted this to a csv file using the code import csv def export_to_csv(tokens): csv_list = [["A", "B", "C", …

Total answers: 3

Regex to append a word after the occurance of any word from a list

Regex to append a word after the occurrence of any word from a list Question: Recently I got this amazing answer on how to remove a word if it occurs after any word in word list1. I wanted to remove the word eat. I was wondering if it is possible to do the reverse, add …

Total answers: 1

Remove a particular word in a list of lists if it appears after a set of words

Remove a particular word in a list of lists if it appears after a set of words Question: I have a list of words list1=[‘duck’,’crow’,’hen’,’sparrow’] and a list of sentences list2=[[‘The crow eats’],[‘Hen eats blue seeds’],[‘the duck is cute’],[‘she eats veggies’]] I want to remove every occurance of the word ‘eats’ if it appears exactly …

Total answers: 2

Check if a word exists at a particular position of a list

Check if a word exists at a particular position of a list Question: Suppose I have a list of lists. List1=[["Red is my favorite color."],["Blue is her favorite."], ["She is really nice."]] Now I want to check if the word ‘is’ exists after a certain set of words. I made a word lise word_list=[‘Red’, ‘Blue’] …

Total answers: 3

Count number of occurrences of dictionary values as nested list based on a query

Count number of occurrences of dictionary values as nested list based on a query Question: I built this inverted index: { ‘experiment’: {‘d1’: [1, [0]], …, ‘d30’: [2, [12, 40]], …, ‘d123’: [3, [11, 45, 67]], …}, ‘studi’: {‘d1’: [1, [1]], ‘d2’: [2, [0, 36]], …, ‘d207’: [3, [19, 44, 59]], …} } For example, …

Total answers: 1