list

Maximum value of a list according to another list in Python

Maximum value of a list according to another list in Python Question: I have two lists res2 and Cb. I want to print maximum value according to an operation as shown below but I am getting an error. I present the expected output. res2=[3, 4, 6] Cb=[[0,10,20,30,40,50,60]] for i in range(0,len(res2)): Max=max(Cb[0][res2[i]]) print(Max) The error …

Total answers: 1

Get dict from list of dicts with the maximum of two items

Get dict from list of dicts with the maximum of two items Question: I would like to get the dict in a list of dicts which has the maximum of two values: manager1={"id":"1","start_date":"2019-08-01","perc":20} manager2={"id":"2","start_date":"2021-08-01","perc":20} manager3={"id":"3","start_date":"2019-08-01","perc":80} manager4={"id":"4","start_date":"2021-08-01","perc":80} managers=[manager1,manager2,manager3,manager4] I want to select the managers that have the latest start date, then get the manager with the …

Total answers: 1

manipulating 3D array in python

manipulating 3D array in python Question: I’m getting the following error when I run the code given below. Still learning Python, so where am I going wrong in my understanding ? What is the fix? Traceback (most recent call last): File "main.py", line 26, in cube[1:3, 1:3]= [‘‘, ‘‘, ‘*’] TypeError: list indices must be …

Total answers: 1

Can python list sort key function take index instead of an element?

Can python list sort key function take index instead of an element? Question: Take a look at this code: points = […] properties = [compute_point_property(point) for point in points] points.sort(?) Here I have a list of points, and I compute a property of each point. Then I need to sort the points by their corresponding …

Total answers: 1

How to create subelements with conditions in list?

How to create subelements with conditions in list? Question: I have a list like this a = [3, 2, 1, 2, 3, 1, 3, 1, 2] I’m trying to get a new list with elements separated in sublist for following conditions: 1-) Separate in sublists the sequences from 1 to N (N in this case …

Total answers: 4

Count dictionary keys and argmax in a list of list

Count dictionary keys and argmax in a list of list Question: Given: import numpy as np list_of_list = [ [‘ccc’, ‘cccc’, ‘b’, ‘c’, ‘b’], [‘ab’, ‘b’, ‘b’, ‘aa’], [‘c’, ‘b’, ‘c’, ‘c’, ‘b’, ‘c’], [‘bb’, ‘d’, ‘c’], ] my_dict = {key: None for key in ‘abcde’} list_of_list is simplified in this test example but it …

Total answers: 1

Find timestamp difference in dictionary values within list of dictionary and capture dictionary with max difference to previous

Find timestamp difference in dictionary values within list of dictionary and capture dictionary with max difference to previous Question: I have a list of dictionary like below : [ {‘dt’: ‘2023-04-08T18:04:33.476+00:00’, ‘msg’: ‘VWX’ }, {‘dt’: ‘2023-04-08T18:04:16.814+00:00’, ‘msg’: ‘STU’ }, {‘dt’: ‘2023-04-08T18:01:40.504+00:00’, ‘msg’: ‘PQR’ }, {‘dt’: ‘2023-04-08T18:01:40.345+00:00’, ‘msg’: ‘MNO’ }, {‘dt’: ‘2023-04-08T18:01:40.068+00:00’, ‘msg’: ‘JKL’ }, {‘dt’: …

Total answers: 2

How to filter entries from a list based on a criteria and get the index in Python?

How to filter entries from a list based on a criteria and get the index in Python? Question: I have a list say list=[1,4,6,3,2,1,8] and I want to filter this list based on the condition that entry>3 and return the corresponding index. So the output should be : [1,2,6] which corresponds to the values 4,6 …

Total answers: 1