I'm not entirely sure what this is called, so I was having a hard time googling it.
I have a collection of custom objects:
from dataclasses import dataclass
@dataclass
class MatchMode:
name: str
description: str
players: int
These objects are instantiated in my main class:
MATCH_MODES = (
MatchMode("Name1", "Description1", 2),
MatchMode("Name2", "Desc2", 4)
)
I'm pulling all of the name's from each MatchMode into another variable like this:
self.matches_queue = {x.name.lower(): [] for x in self.MATCH_MODES}
Now what I'm trying to do is pull a subset of them into a variable in one line:
self.matches_queue = {x.name.lower(): [] for x in //self.MATCH_MODES where Players = 2//}
The problem I'm currently having is I dont know what this is called in order to google how to syntax
things: variable = {x.name.lower(): [] for x in self.MATCH_MODES}
Also, within this function, am I able to put some sort of filtering to only pull MATCH_MODES where Players = 2?
Edit: I ended up just solving it with this. it would be nice to have a more elegant solution:
for modes in self.MATCH_MODES:
if modes.players == 2:
self.two_player_formats[modes.name.lower()] = []