Philipp’s Reviews > Fluent Python: Clear, Concise, and Effective Programming > Status Update
Philipp
is on page 50 of 790
This will take a looong time, but already interesting - how to use __getitem__, __str__, etc. in your methods effectively, how to use generator expresions and list comprehension, all for advanced Python programmers
— Sep 12, 2017 07:38AM
Like flag
Philipp’s Previous Updates
Philipp
is on page 120 of 790
Lots of useful knowledge:
In other words, the end result of this line
my_dict.setdefault(key, []).append(new_value)
is the same as running
if key not in my_dict:
my_dict[key] = [] my_dict[key].append(new_value)
except that the latter code performs at least two searches for key—three if it’s not found—while setdefault does it all with a single lookup.
— Oct 13, 2017 08:20PM
In other words, the end result of this line
my_dict.setdefault(key, []).append(new_value)
is the same as running
if key not in my_dict:
my_dict[key] = [] my_dict[key].append(new_value)
except that the latter code performs at least two searches for key—three if it’s not found—while setdefault does it all with a single lookup.

