Skip to content
Advertisement

Tag: list

Sort one inside another

I have a class Person that contains names and hobbies. Then there’s a list that contains people. person1 = Person(“MarySmith”, [“dancing”, “biking”, “cooking”]) person2 = … people = [person1, person2,..] I need to return a list of people sorted alphabetically by their name, and also sort their list of hobbies alphabetically. This is what I have so far: This is

Repeatedly sample and combine elements of a list

Suppose we have a list L = [‘a’, ‘b’, ‘c’], I would like to perform a group sampling of L to generate an expected result: We can see, in this final output, a list of lists, its each element, there are no repeated elements without considering the order. How to implement it in Python? Answer One way of doing it

Creating a list given an equation with no spaces

I want to create a list given a string such as ‘b123+xyz=1+z1$’ so that the list equals [‘b123’, ‘+’, ‘xyz’, ‘=’, ‘1’, ‘+’, ‘z1’, ‘$’] Without spaces or a single repeating pattern, I do not know how to split the string into a list. I tried creating if statements in a for loop to append the string when it reaches

How to use a dictionary to modify an array in python

I am trying to use a dictionary (created by reading the content of a first file) to modify the content of an array(created by reading the content of a second file) in order to return as many modified arrays as their are keys in the dictionary with the modification corresponding the position and change in the original array indicated in

Find max value of a column based on another in python

i have 2d list implementation as follows. It shows no. of times every student topped in exams:- i have another list of unique students as follows:- which i want to display student ranking based on their distinctions as follows:- What built in functions can be useful. I could not pose proper query on net. In other words i need python

Return decimal fields from list

I have a generator which yields to datatype on is decimal and other is string i need the method to just return the decimal get_amount() now it is returning [(Decimal(‘1950.00′), ’06/16/2020’), (Decimal(‘4500.00′), ’06/16/2020’)] I want the list to be returned as formatted how can i do that ‘${:0,.2f}’.format(Decimal(‘1950.00’) which is in my list) so the end result would be like

Advertisement