sorting

How to use a lambda function to sort a dictionary with a nested list?

How to use a lambda function to sort a dictionary with a nested list? Question: I’ve been trying to sort a dictionary based on largest to lowest values. The dictionary is structured like this: testing = {"third":[1,89],"first":[5,46],"second":[3,59]} The issue I’m coming across is that I’m not entirely sure as to how I can sort this …

Total answers: 1

How do I sort a dataframe by distance from zero value

How do I sort a dataframe by distance from zero value Question: I’ll start by saying I am a Python beginner, I did try and find an answer to this via similar questions but I’m struggling to grasp some of the solutions in order to tailor them for my own use. If I have a …

Total answers: 2

How to correctly use typing for a sort key function

How to correctly use typing for a sort key function Question: For this sort key method: def srt(self,r:Optional[Colour])->Optional[int]: if not isinstance(r,Colour): return None return r.index used in a later method in the same class (NOT Colour): items=sorted(self.__dict__.values(),key=self.srt) results in this error from mypy: error: Argument "key" to "sorted" has incompatible type "Callable[[Optional[Colour]], Optional[int]]"; expected "Callable[[Any], …

Total answers: 1

Sorting pandas groupby output

Sorting pandas groupby output Question: I have a dataframe that looks like name performance year bob 50 2002 bob 90 2005 bob 82 2010 joey 50 2015 joey 85 2013 joey 37 1990 sarah 90 1994 sarah 95 2020 sarah 35 2013 I would like groupby name and compute average performance while only displaying the …

Total answers: 1

How to split a list into sublists with specific range for each sublist?

How to split a list into sublists with specific range for each sublist? Question: I want to split a list into sublist with specific ‘if statement’ for each sublist. For examle: input: a = [1, 2, 7.9, 3, 4, 3.7, 5, 6, 2.2, 7, 8, 1.2, 5.7] output: b = [[1, 1.2, 2], [2.2, 3, …

Total answers: 2

Sorting a list using sorted, key and lambda

Sorting a list using sorted, key and lambda Question: i have this list which is a z3 model: list = [x_2 = 0, x_1 = 1, x_3 = 27, x_11 = 1, x_18 = 4, x_17 = 6, x_26 = 4, x_12 = 4, x_7 = 2, x_22 = 8, x_23 = 27, x_21 = …

Total answers: 1

Using default dictionaries problem (python)

Using default dictionaries problem (python) Question: I have a slightly weird input of data that is in this format: data = { ‘sensor1’: {‘units’: ‘x’, ‘values’: [{‘time’: 17:00, ‘value’: 10}, {‘time’: 17:10, ‘value’: 12}, {‘time’: 17:20, ‘value’ :7}, …]} ‘sensor2’: {‘units’: ‘x’, ‘values’: [{‘time’: 17:00, ‘value’: 9}, {‘time’: 17:20, ‘value’: 11}, …]} } And I …

Total answers: 1

Python – How to sort a 2d array by different order for each element?

Python – How to sort a 2d array by different order for each element? Question: I just want to clear out that I am new to coding. I am trying to solve a problem set that counts the occurrence of characters in a string and prints out the 3 most reoccurring characters Heres the code …

Total answers: 2

How to sort a list of strings containing letters and numbers

How to sort a list of strings containing letters and numbers Question: I am trying to sort a list containing strings that are written in a certain format. Here is an example of said list: numberList = [‘Task #59;’, ‘Task #40.5; additional’, ‘Task #40.9; test’, ‘Task #40; Task Description Difference; test’, ‘Task #11;’, ‘Task #12;’, …

Total answers: 1

How to print a list value one below another

How to print a list value one below another Question: I need to sort a ranking of points by descending order. The users and points are inside lista_ranking which includes de following code: [{‘partido’: {‘codigo’: ‘AAA’, ‘fecha’: datetime.date(2022, 11, 20), ‘hora’: ’13:00hs’, ‘equipo_local’: ‘Catar’, ‘equipo_visitante’: ‘Ecuador’, ‘estado’: ‘Finalizado’, ‘goles_local’: 0, ‘goles_visitante’: 1}, ‘usuario’: {‘cedula’: ‘123’, …

Total answers: 2