list

List of lists of mixed types to numpy array

List of lists of mixed types to numpy array Question: I have data imported from csv and they are stored in list of lists as: data=[[‘1’, ‘ 1.013831’, ‘ 1.713332’, ‘ 1.327002’, ‘ 3.674446’, ‘ 19.995361’, ‘ 09:44:24’, ‘ 2.659884’], [‘2’, ‘ 1.013862’, ‘ 1.713164’, ‘ 1.326761’, ‘ 3.662183’, ‘ 19.996973’, ‘ 09:49:27’, ‘ 2.668791’], …

Total answers: 1

Match element then remove both elements

Match element then remove both elements Question: My list consists on several items: ["book","rule","eraser","clipboard","pencil",etc] Let say I have an element ["book"] and I want to match with another element ["rule"] with the same len (4). then I want to remove both elements from the list. ["eraser","clipboard","pencil",etc] I tried using a for loop and zip(lists, lists[1:]) …

Total answers: 5

Python comparison problem for wordle type game

Python comparison problem for wordle type game Question: I am making a wordle game in python. For that i need to compare the wordle word(mentioned as random_word in the code) to the input by user. The problem is i am unable to devise a method to handle repititions of letters in any word. Here is …

Total answers: 3

How can I sort elements of list in function?

How can I sort elements of list in function? Question: Why I got: None None def odd_even(*number): even = [] odd = [] for i in number: if i % 2 == 0: even.append(i) else: odd.append(i) print(even.sort()) print(odd.sort()) odd_even(1,5,7,8,4,3,26,59,48,7,5,45) I just tried sorting elements of list But result is None None Asked By: Necip Arda …

Total answers: 2

TypeError: object is not iterable when trying to iterate over a list

TypeError: object is not iterable when trying to iterate over a list Question: I have written a code that is supposed to iterate over a list of numbers and perform certain operations on each element. However, I’m getting the following error message: ‘TypeError: object is not iterable’. Here is the relevant snippet of code: my_list …

Total answers: 2

Why can't I use .reverse on a specific range in a list python?

Why can't I use .reverse on a specific range in a list python? Question: I am writing a simple script, where I have a list of character and I want to loop over this list and reverse the ordered of 3 elements at a time. Ex. List: a,b,c,d,e,f ; Reversed list: c,b,a,f,e,d. I tried to …

Total answers: 2

Removing elements of one list wth respect to the other in Python

Removing elements of one list wth respect to the other in Python Question: I have lists J and Indices. I want to remove elements of J according to locations specified in Indices. For example, Indices[0]=1 and Indices[1]=2. This means that J[0][1] and J[0][2] should be removed in one go. But I am getting an error. …

Total answers: 1

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