[Tutor] Efficiency

naheed arafat naheedcse at gmail.com
Sun Jun 26 04:41:06 CEST 2011


On Sat, Jun 25, 2011 at 9:38 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:

>
> "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
>
>
> 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 at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110626/99d03443/attachment-0001.html>


More information about the Tutor mailing list