Easier way to do this?
Chris Angelico
rosuav at gmail.com
Wed Oct 4 22:45:58 EDT 2017
On Thu, Oct 5, 2017 at 11:11 AM, Irv Kalb <Irv at furrypants.com> wrote:
> # If we have not seen this employee name before, add it to the dictionary
> # like key value pair: '<Employee Name>': [0, 0]
> if not(name in employeeDataDict):
> salesCountDict[name] = [0, 0]
Python provides a "not in" operator, which is far superior to
parenthesizing the expression. But, even better, you can use a
defaultdict to create this automatically - and you could even, with a
slight tweak, make use of collections.Counter to do all the work for
you.
ChrisA
More information about the Python-list
mailing list