list

How to pad 0s to garantee same length while iterating over two lists?

How to pad 0s to garantee same length while iterating over two lists? Question: My inputs are : x = [‘A’, ‘B’, ‘B’, ‘C’, ‘D’, ‘D’, ‘D’] y = [ 4 , 3 , 5 , 9 , 1 , 6 , 2 ] And I’m just trying to make this dictionnary. {‘A’: [4, 0, …

Total answers: 2

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

Can't find common elements is two lists

Can't find common elements is two lists Question: I’m writing a little python program, which is supposed to find the greatest common divisor between two numbers. Until now everything went fine but I can’t get the program to find the correct common elements in the two lists the program provides. Also you can see that …

Total answers: 1

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