>>> string.joinfields( ['a', 'b', 'c', 'd', 'e'], '' ) # list to string
'abcde'
Since string.joinfields is REALLY usually (builtin) strop.joinfields,
this one is effectively a _built-in_ operation.
>>> map( None, 'abcdefg' ) # string to list
['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> map( None, ( 1,2,3,4,5,6 ) ) # tuple to list
[1, 2, 3, 4, 5, 6]
There is a note in bltinmodule.c that 'map( None, seq )' could
probably be made into a more effecient special case. Since
map-None is also a quick notation for a transpose operation,
optomizing that case would be useful.
>>> map( None, [1,2,3], [10,20,30], [100,200,300] )
[(1, 10, 100), (2, 20, 200), (3, 30, 300)]
>>> reduce( lambda a,b: a + (b,), 'abcdefg', ()) # string to tuple
('a', 'b', 'c', 'd', 'e', 'f', 'g')
>>> reduce( lambda a,b: a + (b,), [1,2,3,4,5], () ) # list to tuple
(1, 2, 3, 4, 5)
These two are the ones that that take a minute to figure out or
remember, and are neither builtin, nor optimisable in that form.
string-to-tuple wasn't even on your list -- I don't think it is
a very necessary feature. But list-to-tuple is actually one I
could often use: 'apply' takes a function and a *tuple*, and I often
find myself wanting to apply a method to a list of args. ( But maybe
this is not longer true now that we have 'map' ! I haven't hit that
need lately, so maybe it's easier to avoid now. )
So, my vote would be:
- definitely:
optimize the exiting map( None, ... ) special case
- and maybe:
add a fast tuple( seq ) builtin function.
- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
- UVA Department of Molecular Physiology and Biological Physics