"Gregory Ewing" <greg.ew...@canterbury.ac.nz> wrote in message news:cr5sc6fgfm...@mid.individual.net... > Frank Millman wrote: > > The absolutely clearest way to write it would > probably be > > def f(things = None): > "things is a mapping of stuff to be operated on" > if things: > for key in things: > value = things[key] > ... > > A default value of None is a well-established idiom > for "this parameter is optional", and "if x:" is > idiomatic for "if I've been given an x", so writing it > that way has the best chance of passing the "pretty much > what you expect" test for good code. :-) >
Thanks, Greg, that makes a lot of sense. My original method of using 'z=[]' worked, but would cause a reviewer to stop and think about it for a moment. Changing it to 'z=()' would have pretty much the same effect. Using 'z=None' would cause the least hesitation, and is therefore I think the most pythonic. It does require an additional test every time the function is called, but the effect of that in my application is virtually zero. If the overhead did become an issue, Dave's suggestion of 'z=EMPTY_LIST' would be a good solution. Frank -- https://mail.python.org/mailman/listinfo/python-list