Re: [Tutor] how to calculate execution time and complexity

2011-10-27 Thread Praveen Singh
.

> Thanks Christian for your links and code
>
>
> ___
> Tutor maillist  -  Tutor@python.org
>
> To unsubscribe or change subscription 
> options:http://mail.python.org/mailman/listinfo/tutor
>
>
> Below [1] is how I would write it, which is simply a re-factoring of your
> code so it's cleaner and more compact.  For calculating execution time you
> can use the `timeit` module [2] and for more in-depth analysis you can look
> at `profile` [3] and further to the bare-bones `dis` [4].
>
> [1]
> >>> def splitWord(word, number):
> ... x = []
> ... for y in xrange(0, len(word), number):
> ... x.append(word[y:y+number])
> ... return x
> ...
> >>> splitWord('google', 1)
> ['g', 'o', 'o', 'g', 'l', 'e']
>
> >>> splitWord('google', 2)
> ['go', 'og', 'le']
> >>> splitWord('google', 3)
> ['goo', 'gle']
> >>> splitWord('google', 4)
> ['goog', 'le']
> >>> splitWord('google', 5)
> ['googl', 'e']
> >>> splitWord('google', 6)
> ['google']
> >>> splitWord('google', 7)
> ['google']
>
> [2] http://www.doughellmann.com/PyMOTW/timeit/
> [3] http://www.doughellmann.com/PyMOTW/profile/index.html#module-profile
> [4] http://www.doughellmann.com/PyMOTW/dis/
>
> --
>
> Christian Witts
> Python Developer
>
> **
>



-- 
www.tricksfind.blogspot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to calculate execution time and complexity

2011-10-27 Thread Praveen Singh
>>> 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...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] 12 hr to 24 hr time conversion

2011-10-26 Thread Praveen Singh
How can i convert this-

>>>time24hr('12:34am')
 '0034hr'

i searched in date module but i am not able to figure out what how to do
this...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to print corresponding keys in Dictionary

2011-10-24 Thread Praveen Singh
In Dictionary-
How to print corresponding keys if the values of dictionary is given??

-d={'a':1,'b':2,'c':3}
-i can print the corresponding values by using get() method-
- d.get('a')
-1

What if i have to print reverse???
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] functions and default argument

2011-10-21 Thread Praveen Singh
In function-

"Default value is *evaluated only once*.This makes different when the
default is a mutable object such as a list, dictionary or instance of most
classes."

I am not getting it properly-evaluated once?? different behaviour???--
please explain this.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] problem with using set

2011-10-13 Thread Praveen Singh
i have two questions-
1.>>> removeLetter("hello", "l")
   >>>'heo'

To tackle this problem i am using set so that i can remove duplicates.
def removeLetter(word,letter)
set(word).remove(letter)
return ''.join(set(word))

I am not getting right answer.I think i am not using sets correctly.please
help!!!

Approach:-
>>> a='hello'
>>> set(a)
set(['h', 'e', 'l', 'o']), so i am thinking somehow if i remove 'l' and i
join the string, i will get the desired output.

2.
>>> a='microsoft'
>>> set(a)
set(['c', 'f', 'i', 'm', 'o', 's', 'r', 't'])
>>> print ''.join(set(a))
cfimosrt

When i print "Hello", i get the output as "helo"(in same sequence) but when
i write "microsoft" i get this-"cfimosrt". So, it means i can't predict the
outcome of set(a)??
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] I am trying to print list elements but i am getting 'none'

2011-10-10 Thread Praveen Singh
This is my code-
 def getNumbers(num):
myList=[]
for numbers in range(0,num,2):
  print myList.append(numbers)


output-
>>> getNumbers(10)
None
None
None
None
None

Then i find out that list.append doesn't return anything.Then what should i
use for this kind of operation.but if i do something like this on idle's
interpreter it gives me answer-
>>> myList=[]
>>> myList.append(8)
>>> print myList
[8]

Confused!!!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help me in this programme

2011-10-06 Thread Praveen Singh
this is one of the problem based on list which i found at pyschool.

CountWords("google")
[('e',1),('g',2),('l',1),('o',2)]

by the level of this question you can easily understand i am new in
python.the problem i am facing is how to make set of word and count(e,1) and
add this to list??
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] where to look for python codes

2011-09-29 Thread Praveen Singh
i am a beginner in python.i am not asking about any books here.As i have
heard one essential steps of learning is to look for some good python
codes.So, can you guys please and please suggest me some sites or some small
projects where i can find these codes?? please remember i am at a BEGINNER's
level!!

thank you!!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor