Here is my dictionary structure:
{
"432701228292636694" : {
"432739261603905537" : {
"channels" : {
"LoL Duos" : {
"capacity" : 2,
"rooms" : [
"432741328477093889"
]
},
"LoL Quads" : {
"capacity" : 4,
"rooms" : [
"432741635852599297"
]
},
"LoL Teams" : {
"capacity" : 5,
"rooms" : [
"467708831695110154"
]
},
"LoL Trios" : {
"capacity" : 3,
"rooms" : [
"432741537890304030",
"468096902055985152"
]
}
},
"perms" : {
"453625621604728839" : {
"read_messages" : false
},
"461654834689474560" : {
"read_messages" : false
}
}
},
"432739461475074049" : {
"channels" : {
"FN Duos" : {
"capacity" : 2,
"rooms" : [
"432740789660155904"
]
},
"FN Squads" : {
"capacity" : 4,
"rooms" : [
"432740857268142081"
]
},
"FN Trios" : {
"capacity" : 3,
"rooms" : [
"467707010746417172"
]
}
},
"perms" : {
"453625621604728839" : {
"read_messages" : false
},
"461654872815697931" : {
"read_messages" : false
}
}
},
"436634548051378186" : {
"channels" : {
"OW Duos" : {
"capacity" : 2,
"rooms" : [
"436636544229441567"
]
},
"OW Quads" : {
"capacity" : 4,
"rooms" : [
"436636615167705089"
]
},
"OW Teams" : {
"capacity" : 5,
"rooms" : [
"467707823954984971"
]
},
"OW Trios" : {
"capacity" : 3,
"rooms" : [
"436636575036866570"
]
}
},
"perms" : {
"453625621604728839" : {
"read_messages" : false
},
"461654908329000972" : {
"read_messages" : false
}
}
}
}
}
What I'm wanting to do is check if a string matches any of the values of any rooms
. I've found a really messy way to do it like this:
for category_id in self.gaming_db[server.id]:
channel_names = self.gaming_db[server.id][category_id]['channels']
for channel_name in channel_names:
room_ids.extend([server.get_channel(x) for x in self.gaming_db[server.id][category_id]['channels'][channel_name]['rooms']])
This is if you assume self.gaming_db
is this dictionary. Is there a more Pythonic way to do this? I think it has something to do with list comprehensions using lambda? I really don't understand that much so far.