From: Benjamin Kaplan on
On Wed, Jun 9, 2010 at 10:25 PM, Qijing Li <qjing.li(a)gmail.com> wrote:
> Thanks for your reply.
> I'm trying to understand python language deeply and  use it efficiently..
> For example: How the operator "in" works on list? the running time is
> be O(n)?  if my list is sorted, what the running time would be?
>
>

Still O(n). Python doesn't know that your list is sorted, so nothing
changes. And the check to make sure it is sorted would be O(n) anyway.
From: Ian Kelly on
On Wed, Jun 9, 2010 at 11:54 PM, Benjamin Kaplan
<benjamin.kaplan(a)case.edu> wrote:
> On Wed, Jun 9, 2010 at 10:25 PM, Qijing Li <qjing.li(a)gmail.com> wrote:
>> Thanks for your reply.
>> I'm trying to understand python language deeply and  use it efficiently.
>> For example: How the operator "in" works on list? the running time is
>> be O(n)?  if my list is sorted, what the running time would be?
>>
>>
>
> Still O(n). Python doesn't know that your list is sorted, so nothing
> changes. And the check to make sure it is sorted would be O(n) anyway.

However, if the programmer knows that the list is sorted, then the
following would be O(log n):

from bisect import bisect_left

index = bisect_left(the_list, item)
item_in_list = index < len(the_list) and the_list[index] == item

But in general, if you want the "in" operator to be efficient, then
you probably want to use a set or a dict, not a list.

Cheers,
Ian
From: Thomas Jollans on
On 06/10/2010 07:25 AM, Qijing Li wrote:
> Thanks for your reply.
> I'm trying to understand python language deeply and use it efficiently.
> For example: How the operator "in" works on list? the running time is
> be O(n)? if my list is sorted, what the running time would be?

There is excellent documentation of the language and standard library at
http://docs.python.org/ .

Otherwise, just download the Python source code! You know it's free. I
think it's pretty well organised, though I haven't worked with it a lot
yet myself. Just poke around!

Have fun,
Thomas

>
>
>
> On Wed, Jun 9, 2010 at 5:59 PM, geremy condra <debatem1(a)gmail.com
> <mailto:debatem1(a)gmail.com>> wrote:
>
> On Wed, Jun 9, 2010 at 5:28 PM, Leon <qjing.li
> <http://qjing.li>@gmail.com <http://gmail.com>> wrote:
> > Hi, there,
> > I'm trying to read the source code of python.
> > I read around, and am kind of lost, so where to start?
> >
> > Any comments are welcomed, thanks in advance.
>
> Are you trying to find out more about python-the-language,
> or the interpreter, or the stdlib, or trying to make some
> specific change, or...?
>
> Geremy Condra
>
>

From: News123 on
Leon wrote:
> Hi, there,
> I'm trying to read the source code of python.dd
> I read around, and am kind of lost, so where to start?
>
> Any comments are welcomed, thanks in advance.


I use my favourite text editor with syntax highlighting.

Next to it I use a web browser with pydoc and google.

If uou're looking for an IDE that will help you a little more navigating
in python code, then you could look at

Eclipse
or
Netbeans
both support python

both are rather heavy weapons though.
From: pradeepbpin on
On Jun 10, 1:15 pm, News123 <news1...(a)free.fr> wrote:
> Leon wrote:
> > Hi, there,
> > I'm trying to read the source code of python.dd
> > I read around, and am kind of lost, so where to start?
>
> > Any comments are welcomed, thanks in advance.
>
> I use my favourite text editor with syntax highlighting.
>
> Next to it I use a web browser with pydoc and google.
>
> If uou're looking for an IDE that will help you a little more navigating
> in python code, then you could look at
>
> Eclipse
> or
> Netbeans
> both support python
>
> both are rather heavy weapons though.


In my opinion, pydoc would be a good choice. I am a fan of it.