I'm trying to understand list comprehension in python using this example -
async def on_member_update(before, after):
stream = [i for i in after.activities if str(i.type) == "ActivityType.streaming"]
if stream:
The above example is using the api from discord.py. Streaming is a member activity - https://discordpy.readthedocs.io/en/stable/api.html#activity . ActivityType.streaming is a type - https://discordpy.readthedocs.io/en/stable/api.html#discord.ActivityType
What's going on in this loop? I'll try and walkthrough what I may know. So if (i.type)
returns as a string then it would be looping through the characters in the stream list? I'm confused. after.activites
is the member's CURRENT activity. So it'd be streaming. What exactly does (i.type)
represent what how is the loop interacting with after.activites
?
Getting lost. Could someone walk me through the steps of what's happening here? Thank you!