[Tutor] Efficiency
Alan Gauld
alan.gauld at btinternet.com
Sat Jun 25 17:38:59 CEST 2011
"naheed arafat" <naheedcse at gmail.com> wrote
> 1)
>>>> zip('How are you?'.split(' ')[::-1],'i am fine.'.split(' '))
> [('you?', 'i'), ('are', 'am'), ('How', 'fine.')]
>>>> map(lambda i,j:(i,j),'How are you?'.split(' ')[::-1],'i am
> fine.'.split(' '))
> [('you?', 'i'), ('are', 'am'), ('How', 'fine.')]
>
> Which one has better efficiency?
Why not just measure it with timeit?
> 2)
> Is there any way easier to do the following?
> input:
> 'How are you'
> 'I am fine'
> output:
> 'you I are am How fine'
>
> solution:
>>>> ' '.join(reduce(lambda x,y:x+y, zip('How are you'.split('
>>>> ')[::-1],
> 'I am fine'.split(' '))))
That depends on your efiition of easier
There are clearer solutions but they will be more verbose.
Do you measure "easiness" by readability, or by typing effort?
Or something else?
Alan G
More information about the Tutor
mailing list