enhanced map function
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Mar 17 20:31:26 EDT 2011
On Thu, 17 Mar 2011 08:31:28 -0700, Patrick wrote:
> Steven,
>
> Thanks for the info of itertools. It is a great start for me. Overall, I
> agree with you that it is really the user data needs to be sorted out.
> However, novice users may need help on certain patterns such as
> "a=[1,[2,3],4], b=[5,[6,7,8],9,10]".
You have misunderstood me. I'm not saying that you should force the users
to clean up the data (although of course you could do that), but that you
should do so before handing it to map.
Rather than putting all the smarts into enhanced_map, and having it
understand what to do with mismatched nested lists, deep nesting,
integers where you would expect a list, etc., you should write another
function that takes the user's data and adjusts it to some known,
consistent format, and then pass that on to map. Don't have one function
try to do too much.
--
Steven
More information about the Python-list
mailing list