silly idea - interesting problem
Gareth.McCaughan at pobox.com
Wed Oct 24 11:27:21 CEST 2001
Steven D. Majewski wrote:
> On Sat, 20 Oct 2001, Stefan Antoni wrote:
> > i got a silly idea about a small script which takes to strings (lets say
> > "test" and "dust") and mixes them to "tdeusstt".
> > i tried to code it because i thought it would be easy, but now i cannot
> > find out _how_ to do it ;)
> > i tried to "list()" the string and mix the items. but ...
> > Anybody has a hint or even a solution?
> >>> import operator
> >>> reduce( operator.__add__, map( operator.__add__, 'test', 'dust' ), '' )
Better to use string.join (or, in more recent Python, the "join"
method on string objects) instead of the outermost reduce, so as
not to lose horribly when the result is very long.
Gareth McCaughan Gareth.McCaughan at pobox.com
.sig under construc
More information about the Python-list