The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

Mark Lawrence breamoreboy at yahoo.co.uk
Wed Mar 23 19:21:38 EDT 2016


On 23/03/2016 16:24, Random832 wrote:
>
>
> On Wed, Mar 23, 2016, at 12:08, Mark Lawrence wrote:
>>> And doing it 'Pythonically' can lead to suggestions such as the
>>> following the other day:
>>>
>>>    c, psource = psource[0], psource[1:]
>>>
>>> (where psource is a very long string), which even I could tell, from
>>> knowing what goes on behind the scenes, wasn't going to work well
>>> (duplicating the rest of the string roughly every other character).
>>>
>>
>> It would work perfectly. How would it duplicate the rest of the string
>> roughly every other character?
>
> Er, I think he's suggesting that this would be in an inner loop
> (something like while psource: c, psource = psource[0], psource[1:]).
> What I'm not sure of is why he thinks this is pythonic.
>

It was in response to Dennis Lee Bieber 
http://code.activestate.com/lists/python-list/700242/.  Quite why he 
thinks it won't work well I've no idea.  I'd have said it was Pythonic, 
as slicing is a standard idiom.

As for every other character, it again shows his complete ignorance of 
Python.  Although thinking about it, it you were to skip every character 
that needed processing, surely that would be really fast?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list