Skip to content

Tag: python

Initialize class instance in a loop over a list

I have a class where I assign a rating to each instance. I would like to be able to loop over a list of ratings, and create an instance for each rating, so if I have a list of ratings and team names, something like this: The above is not defining an instance of Team like I want it to.

Defining two objects at once using list comprehension

I have a list of dicationaries list_dic each containing the keys id;name. From those keys I’d like create two lists. I would like to use a list comprehension for this task, e.g. The issue here is I’m looping twice which is probably not a smart thing to do. Is there a way to use a list comprehensio…