-1

i have a list of strings

list1 = ["object1", "object2", "object3"]

and i want to convert it into a list of object

the main idea is to have a function that returns a list in ascending order based on the value of an attribute of all instances

class Players: # this is the class and score is the value
def __init__(self, username, score):
    self.username = username
    self.score = score 

I need a function that as soon as it is called returns a dictionary sorted in ascending order by the "score" value that contains username : score

thank you so much

Dev.dsam
  • 1
  • 2
  • 1
    On a side note, your terminology is off. In Python literally everything is an object. The list is an object, the strings are objects, the players are objects. The Player is object. – Markus Hirsimäki May 15 '22 at 09:12
  • Welcome to Stack Overflow. In the future, [please try to search](https://meta.stackoverflow.com/questions/261592) before asking ([on the Internet](https://duckduckgo.com/?q=python+sort+by+attribute), not just on Stack Overflow); try to describe the problem clearly, with an [mre] (show an exact possible input to the process, and make sure it is clear exactly what should happen; and make sure the input is interesting enough that simple code wouldn't get the answer by accident); and most importantly **ask a specific question**. – Karl Knechtel May 15 '22 at 09:17

0 Answers0