enhanced map function

Patrick zxpatric at gmail.com
Thu Mar 17 11:31:28 EDT 2011


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]". We could just draw our line
saying that similarly nested inputs could be adjusted even though the
members aren't exactly on one-to-one mapping and we won't getting any
deeper for complicated cases such as "a = [1, 2, [3, 4]]; b = [1, [2,
[3,4]], [4,5], 6]".

> enhanced_map([1, [2,3, [4,5], 6], 7], [8, [7,6, [5,4], 3], 2])
> should be the same as
> map([1, 2, 3, 4, 5, 6, 7], [8, 7, 6, 5, 4, 3, 2])

I don't expect the drop. The original nested structure is very
important.


> What do you expect to happen if the sub-sequences don't match up exactly?
> E.g. a = [1, 2, [3, 4]]; b = [1, [2, 3], 4]
>
> What do you expect to happen if the shorter list is empty?
> E.g. a = [1, 2, [3, 4], 5]; b = [1, 2, [], 3]

There are modes called "shortest" and "longest" (and
"AllCombination"/"Cross" which is more complex).

For case  a = [1, 2, [3, 4],4]; b = [1, [2, 3], 4,5]

shortest:
   a will be adjusted to [1, [3, 4],4]
   b will be adjusted to [1, [2, 3],4]

longest:
   a will be adjusted to [1, 2,[3, 4],4,4]
   b will be adjusted to [1, 1,[2, 3],4,5]

As I said previously, the enhance_map function will only handle
limited "unmatch" cases and the line will need to be drawn carefully.

Thanks
-Patrick.



More information about the Python-list mailing list