On Sat, Jun 25, 2011 at 9:38 PM, Alan Gauld <alan.ga...@btinternet.com>wrote:
> > "naheed arafat" <naheed...@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 > > > Here I meant the term "easier" by conceptually easier.. I mean any Conceptually neater way other than the following steps: for the given input: 1. ['you', 'are', 'How'] 2. ['I', 'am', 'fine'] 3. [('you', 'I'), ('are', 'am'), ('How', 'fine')] 4. ('you', 'I', 'are', 'am', 'How', 'fine') i.e applying + operator cumulatively. sorry for my english. > ______________________________**_________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor> >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor