Category : list

Suppose I have a list of lists like so: [ [‘group1’, ‘type1’, ‘2021-3-24’], [‘group1’, ‘type1’, ‘2021-3-25’], [‘group1’, ‘type1’, ‘2021-3-26’], [‘group2’, ‘type2’, ‘2022-5-21’], [‘group2’, ‘type2’, ‘2021-1-12’], [‘group2’, ‘type2’, ‘2021-3-26’], ] and I want these results: [ [‘group1’, ‘type1’, ‘2021-3-26’], [‘group2’, ‘type2’, ‘2022-5-21’], ] where each list in the parent list is grouped by group and type ..

Read more

I tried to iterate over each word in the sentence after making a list of the sentence words and add ‘l’ until the length of character in each word reached the length of the maximum sized word. but using while loop, it says that object has no length. def convert_string(ip): ip_list = ip.split() print(ip_list) max_length ..

Read more

I have the following list: p = [(58.5, -4.5), (67.5, -4.5), (76.5, -4.5), (76.5, 4.5), (67.5, 4.5), (58.5, 4.5), (67.5, 4.5), (58.5, 4.5), (58.5, 13.5), (49.5, 13.5), (40.5, 13.5), (49.5, 13.5), (40.5, 13.5), (40.5, 22.5), (31.5, 22.5), (22.5, 22.5), (31.5, 22.5), (22.5, 22.5), (22.5, 31.5), (13.5, 31.5), (4.5, 31.5), (13.5, 31.5), (4.5, 31.5), (4.5, 40.5), ..

Read more

I am trying to categorize a dataset based on the string that contains the name of the different objects of the dataset. The dataset is composed of 3 columns, df[‘Name’], df[‘Category’] and df[‘Sub_Category’], the Category and Sub_Category columns are empty. For each row I would like to check in different lists of words if the ..

Read more

I am trying to implement a simple BFS code. Code: def initalizeVertex(): n = int(input(‘Enter the no. of vertices.n’)) for vertex in range(n): Vertex.append(vertex) node_adjacency[vertex] = [] def initalizeUndirectedEdges(): n = int(input("Enter the no. of edges.n")) print("Enter the space seperated edges.") for i in range(n): a,b = map(int,input().split()) node_adjacency[a].append(b) node_adjacency[b].append(a) def bfs(): current_level = 1 ..

Read more

I have a text file as : sample.txt Hi I am student I am from What I’ve tried is import string import re def read_to_list1(filepath): text_as_string = open(filepath, ‘r’).read() x = re.sub(‘[‘+string.punctuation+’]’, ”, text_as_string).split("n") for i in x: x_as_string = re.sub(‘[‘+string.punctuation+’]’, ”, i).split() print(x_as_string) read_to_list1(‘sample.txt’) This results [‘Hi,’I’,’am’,’student’] [‘I’,’am’,’from’] I want the result as: [[‘Hi,’I’,’am’,’student’],[‘I’,’am’,’from’]] ..

Read more