Empty containers like [] and {} are everywhere in Python. It's super common to see functions start by creating an empty container, filling it up, and then returning the result.
Take this, for example:
def my_func ( ys : dict [ str , int ] ) :
x = { }
for k , v in ys . items ( ) :
if some_condition ( k ) :
x . setdefault ( "group0" , [ ] ) . append ( ( k , v ) )
else :
x . setdefault ( "group1" , [ ] ) . append ( ( k , v ) )
return x
... continue reading