[Tutor] Efficiency
naheed arafat
naheedcse at gmail.com
Sat Jun 25 14:34:17 CEST 2011
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?
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(' '))))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110625/606161ba/attachment.html>
More information about the Tutor
mailing list