[Tutor] how to calculate execution time and complexity
Dave Angel
d at davea.name
Fri Oct 28 09:14:26 CEST 2011
On 10/28/2011 01:38 AM, Praveen Singh wrote:
>>>> splitWord('google', 2)
> ['go', 'og', 'le']
> >>> splitWord('google', 3)
> ['goo', 'gle']
> >>> splitWord('apple', 1)
> ['a', 'p', 'p', 'l', 'e']
> >>> splitWord('apple', 4)
> ['appl', 'e']
>
>
> def splitWord(word, number):
> length=len(word)
> list1=[]
> x=0
> increment=number
> while number<=length+increment:
> list1.append(word[x:number])
> x=x+increment
> number=number+increment
>
> for d in list1:
> if d=='':
> list1.remove('')
> return list1
>
> I am getting the desired output and this code is working fine..but i
> think it is quite bulky for this small operation.
>
> qus.1-- can you guys suggest me some better solution??
> qus 2-- i know writing just a piece of code is not going to help me. i
> have to write efficient code.i want to know how to calculate execution
> time of my code and
> can you guys suggest me some links so that i can learn how to
> find complexity of code??
>
> Thanks in advance...
>
Use the grouper() recipe, shown on the intertools page of the docs:
http://docs.python.org/library/itertools.html
--
DaveA
More information about the Tutor
mailing list