The following question is more along the lines of "good practice" rather
than "how do you do it"   .

If I have a name:value list of values that I want to read into a dict for
ease of lookup, lets define them as:

name  | value
==========
ItemOne : 10
ItemOne : 10
ItemOne : 10
ItemOne : 10
ItemTwo : 20
ItemTwo : 20
ItemTwo : 20
ItemTwo : 20
ItemThree : 30
ItemThree : 30
ItemThree : 30
ItemThree : 30

Now,  obviously there are duplicates in that list.    If I use a simple
loop such as the following:
for each_name in list:
     item[name] = value

Then I will get a dict with three pairs in it:
ItemOne : 10
ItemTwo : 20
ItemThree : 30

Which is what I want.

Now,   MY question is,  is there any harm in creating the dict that way and
looping through all those values multiple times and re-defining the values
constantly (to the same thing).   OR, should I put a check in there such as:

if name not in item:
   # add name and its pair value to dict


In my case I HAVE added checking in but I was wondering if it was really
needed.  Given no matter what, in either case, the resulting dict would be
the same.

Regards,
David
_______________________________________________
melbourne-pug mailing list
[email protected]
https://mail.python.org/mailman/listinfo/melbourne-pug

Reply via email to