Real-world use cases for map's None fill-in feature?

Anders Hammarquist iko at cd.chalmers.se
Mon Jan 9 02:31:53 EST 2006


In article <mailman.194.1136781640.27775.python-list at python.org>,
Raymond Hettinger <python at rcn.com> wrote:
>Request for more information
>----------------------------
>My request for readers of comp.lang.python is to search your own code
>to see if map's None fill-in feature was ever used in real-world code
>(not toy examples).

I had a quick look through our (Strakt's) codebase and found one example.

The code is used to process user-designed macros, where the user wants
to append data to strings stored in the system. Note that all data is
stored as lists of whatever the relevant data type is.

While I didn't write this bit of code (so I can't say what, if any,
alternatives were considered), it does seem to me the most straight-
forward way to do it. Being able to say what the fill-in value should
be would make the code even simpler.

oldAttrVal is the original stored data, and attValue is what the macro
wants to append.

--->8---
    newAttrVal = []
    for x, y in map(None, oldAttrVal, attrValue):
        newAttrVal.append(u''.join((x or '', y or '')))
--->8---

/Anders

-- 
 -- Of course I'm crazy, but that doesn't mean I'm wrong.
Anders Hammarquist                                  | iko at cd.chalmers.se
Physics student, Chalmers University of Technology, | Hem: +46 31 88 48 50
G|teborg, Sweden.           RADIO: SM6XMM and N2JGL | Mob: +46 707 27 86 87



More information about the Python-list mailing list