On Mon, Mar 23, 2015 at 10:17:11PM -0400, Dave Angel wrote:
> On 03/23/2015 09:42 PM, boB Stepp wrote:
> >Can you give me a ballpark number for "large", where this would start
> >making a meaningful difference?
> >
>
> Not really. See Steve's response for some numbers.
o_O
Have you borrowed Gu
On 03/23/2015 10:17 PM, Dave Angel wrote:
On 03/23/2015 09:42 PM, boB Stepp wrote:
Not really. See Steve's
OOPS. Peter's
> response for some numbers. If I had to guess,
I'd say that for lists over 100 items, you should use bisect or
equivalent. But I'd also say you should have one algo
On Mon, Mar 23, 2015 at 08:42:23PM -0500, boB Stepp wrote:
> On Thu, Mar 19, 2015 at 12:10 AM, Dave Angel wrote:
> > The catch to a list comprehension is it has to visit all the elements, while
> > a binary search would visit log-base-2 of them. So instead of 1
> > elements, you'd be searchin
On 03/23/2015 09:42 PM, boB Stepp wrote:
On Thu, Mar 19, 2015 at 12:10 AM, Dave Angel wrote:
The catch to a list comprehension is it has to visit all the elements, while
a binary search would visit log-base-2 of them. So instead of 1
elements, you'd be searching about 14 items.
I suspect
On Thu, Mar 19, 2015 at 4:52 AM, Peter Otten <__pete...@web.de> wrote:
> Dave Angel wrote:
[...]
> By the way, if you were to use a plain old loop the expected speedup over
> the listcomp would be 2. You can break out of the loop when you have found
> the gap, after iterating over one half of the
On Thu, Mar 19, 2015 at 12:10 AM, Dave Angel wrote:
> The catch to a list comprehension is it has to visit all the elements, while
> a binary search would visit log-base-2 of them. So instead of 1
> elements, you'd be searching about 14 items.
I suspected as much, but had not verified this.
Patrick Thunstrom wrote:
The generalized problem:
L = [V0, V1, ..., Vn], where V0 >= V1 >= V2 >= ... >= Vn .
Find index i, such that V[i] >= Vt >= V[i + 1], where Vt is the test
value being searched for. I need to know the indices i and i + 1,
which I need to interpol
>>> The generalized problem:
>>>
>>> L = [V0, V1, ..., Vn], where V0 >= V1 >= V2 >= ... >= Vn .
>>> Find index i, such that V[i] >= Vt >= V[i + 1], where Vt is the test
>>> value being searched for. I need to know the indices i and i + 1,
>>> which I need to interpolate based on where Vt falls.
>>>
Dave Angel wrote:
> On 03/19/2015 12:20 AM, boB Stepp wrote:
>> I hope extolling the beauty and power of Python on this list is
>> allowed, because I have had a large "WOW!!!" moment tonight. I had a
>> problem I was working on at work this afternoon. I have a list of ~
>> 10,000 floating point nu
On 19/03/2015 04:20, boB Stepp wrote:
I hope extolling the beauty and power of Python on this list is
allowed, because I have had a large "WOW!!!" moment tonight. I had a
problem I was working on at work this afternoon. I have a list of ~
10,000 floating point numbers, which run from largest to s
On 03/19/2015 12:20 AM, boB Stepp wrote:
I hope extolling the beauty and power of Python on this list is
allowed, because I have had a large "WOW!!!" moment tonight. I had a
problem I was working on at work this afternoon. I have a list of ~
10,000 floating point numbers, which run from largest t
I hope extolling the beauty and power of Python on this list is
allowed, because I have had a large "WOW!!!" moment tonight. I had a
problem I was working on at work this afternoon. I have a list of ~
10,000 floating point numbers, which run from largest to smallest.
There are duplicates scattered
On Fri, Oct 9, 2009 at 1:21 AM, wesley chun wrote:
> [generator expressions] are
> "lazy" because you iterate over the values one at a time instead of
> creating the entire list. they are slightly slower but save memory.
I don't think you can make a blanket statement comparing speed of list
comp
> I've been studying python now for a few weeks and I've recently come
> into list comprehensions. [...]
> Those make sense to me. The way I understand them is:
> do something to x for each x in list, with an optional qualifier.
that's pretty much correct.
> On the other hand I've seen a few exa
Hello,
On Wed, Oct 7, 2009 at 6:57 AM, Christer Edwards
wrote:
>
> do something to x for each x in list, with an optional qualifier.
>
To be more precise:
http://docs.python.org/tutorial/datastructures.html#list-comprehensions
"Each list comprehension consists of an expression followed by a fo
Christer Edwards schrieb:
I've been studying python now for a few weeks and I've recently come
into list comprehensions. Some of the examples that I've found make
sense, and I find them readable and concise. In particular I'm
referring to the python docs on the topic
(http://docs.python.org/tut
I've been studying python now for a few weeks and I've recently come
into list comprehensions. Some of the examples that I've found make
sense, and I find them readable and concise. In particular I'm
referring to the python docs on the topic
(http://docs.python.org/tutorial/datastructures.html#list
ith a built-in
> would help. Maybe not?
>
> Hope that helps.
>
> Dinesh
>
>
> - Original Message -
> *From:* Kent Johnson <mailto:[EMAIL PROTECTED]>
> *To:* Dinesh B Vadhia <mailto:[EMAIL PROTECTED]>
> *Cc:* tutor@python.org <mail
Alan Gauld wrote:
> One possibility is that the javascript fetches the list back on the
> first few characters and caches it on the browser
Here is an autocomplete widget I use that can do exactly that:
http://www.dyve.net/jquery/?autocomplete
Kent
___
"Kent Johnson" <[EMAIL PROTECTED]> wrote
>> application/service. Each time a user inputs a character, the
>> character
>> is sent to the backend Python program which searches for the
>> character
>> in a list of >10,000 string items. Once it finds the character,
>> the
>> backend will return
Dinesh B Vadhia wrote:
> Kent
>
> I'm using a Javascript autocomplete plugin for an online web
> application/service. Each time a user inputs a character, the character
> is sent to the backend Python program which searches for the character
> in a list of >10,000 string items. Once it finds
My guess, though I'm not sure, is that google uses hashes...
why? Because they're a *ahem* load faster than loops, and the reason
is they replace the repetitive nature of a loop by using some type of
formula. Exactly /how/ this is implemented, I'm not sure.
A simple example of the speed differenc
i think you are using ajax ... which undoubdetly uses an sql database since
its based on queries run from whithin the application in the browser
whithout the need for refreshing the page ... i would suggest you try
serching internet for something like "google autocomplete feature" & i
guess the qu
also if you need to go for 2 results I propose you use filters &
interactive menus which will help you tailor the query to the users desires
& thus limit the query results.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinf
"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote i
> I'm using a Javascript autocomplete plugin for an online
> web application/service. Each time a user inputs a character,
> the character is sent to the backend Python program which
> searches for the character in a list of >10,000 string items.
ed sensible that replacing the for loop with a built-in would help. Maybe
not?
Hope that helps.
Dinesh
- Original Message -
From: Kent Johnson
To: Dinesh B Vadhia
Cc: tutor@python.org
Sent: Wednesday, April 09, 2008 1:48 PM
Subject: Re: [Tutor] List comprehensions
Dinesh B Vadhia wr
On Wed, Apr 9, 2008 at 4:48 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:
> You could use
> [ sys.stdout.write(some operation on item) for item in data ]
>
> but I consider this bad style and I seriously doubt you will see any
> difference in performance.
This really isn't a good idea. It will
On Wed, Apr 9, 2008 at 4:15 PM, Dinesh B Vadhia
<[EMAIL PROTECTED]> wrote:
> Sorry, let's start again.
This version really isn't any more helpful than the first one. I know
you corrected the sample code, but you haven't addressed any of the
fundamental questions that Kent or I asked.
> I want to
Dinesh B Vadhia wrote:
> Here is a for loop operating on a list of string items:
>
> data = ["string 1", "string 2", "string 3", "string 4", "string 5",
> "string 6", "string 7", "string 8", "string 9", "string 10", "string 11"]
>
> result = ""
> for item in data:
> result = item
> pr
a potentially better structure preferably a built-in.
>
> Hope this makes sense! Thank-you.
>
> Dinesh
>
>
>
> - Original Message - *From:* Kent Johnson <[EMAIL PROTECTED]>
> *To:* Dinesh B Vadhia <[EMAIL PROTECTED]>
> *Cc:* tutor@python.org
> *Sent:
l Message -----
From: Kent Johnson
To: Dinesh B Vadhia
Cc: tutor@python.org
Sent: Wednesday, April 09, 2008 12:40 PM
Subject: Re: [Tutor] List comprehensions
Dinesh B Vadhia wrote:
> Here is a for loop operating on a list of string items:
>
> data = ["string 1", "str
On Wed, Apr 9, 2008 at 7:44 PM, Jerry Hill <[EMAIL PROTECTED]> wrote:
> On Wed, Apr 9, 2008 at 7:12 AM, Dinesh B Vadhia
> <[EMAIL PROTECTED]> wrote:
> > I want to replace the for loop with a List Comrehension (or whatever) to
> > improve performance (as the data list will be >10,000]. At each sta
On Wed, Apr 9, 2008 at 7:12 AM, Dinesh B Vadhia
<[EMAIL PROTECTED]> wrote:
> I want to replace the for loop with a List Comrehension (or whatever) to
> improve performance (as the data list will be >10,000]. At each stage of
> the for loop I want to print the result ie.
List comprehensions are fo
Dinesh B Vadhia wrote:
> Here is a for loop operating on a list of string items:
>
> data = ["string 1", "string 2", "string 3", "string 4", "string 5",
> "string 6", "string 7", "string 8", "string 9", "string 10", "string 11"]
>
> result = ""
> for item in data:
> result = item + "\n"
>
Here is a for loop operating on a list of string items:
data = ["string 1", "string 2", "string 3", "string 4", "string 5", "string 6",
"string 7", "string 8", "string 9", "string 10", "string 11"]
result = ""
for item in data:
result = item + "\n"
print result
I want to replace the for loo
On 23 Mrz 2005, [EMAIL PROTECTED] wrote:
> map is (probably) going to be removed in Python3000 :-( So it's
> probably better to not get into the habit of using it.
Au contraire. If enough people use it and are used using it the risk
for `map' getting removed will be a lot lower. Furthermore t
Geez, that's pretty bad. I've got to stop playing with code when I'm tired.
Thanks all.
On Wed, 23 Mar 2005 20:24:32 -, Alan Gauld <[EMAIL PROTECTED]> wrote:
> > Is there a way to apply multiple actions within one list
> comprehension?
>
> Write a function?
>
> def foo(i):
># do stuf
> Is there a way to apply multiple actions within one list
comprehension?
Write a function?
def foo(i):
# do stuff to i
return i
[foo(i) for i in alist]
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tut
Ryan Davis wrote:
I think map is a little cleaner is some cases. Not sure if its more Pythonic,
I'm still trying to figure out exactly what that
means.
map is (probably) going to be removed in Python3000 :-( So it's
probably better to not get into the habit of using it.
--
John.
__
Liam Clarke wrote:
Is there any guides to this (possibly obtuse) tool?
http://docs.python.org/tut/node7.html#SECTION00714
http://www.amk.ca/python/2.0/index.html#SECTION00060
Kent
___
Tutor maillist - Tutor@python.org
htt
Liam Clarke wrote:
Is there any guides to this (possibly obtuse) tool?
Think of it this way. A list comprehension generates a new list. So, you
should think about list comps whenever you have old_list -> new_list
style behavior.
There are two advantages to list comps over map:
1) a list comp can
lf Of Liam Clarke
Sent: Wednesday, March 23, 2005 5:44 AM
To: Tutor Tutor
Subject: [Tutor] List comprehensions
Hi,
Is there a way to apply multiple actions within one list comprehension?
i.e. instead of
a = []
for i in x:
i.pop(3)
g = [ int(item) for item in i]
a.append(g)
Is there
Liam Clarke wrote:
Hi,
Is there a way to apply multiple actions within one list comprehension?
i.e. instead of
a = []
for i in x:
i.pop(3)
g = [ int(item) for item in i]
a.append(g)
You can nest list comps. Except for the pop, the above can be written
a = [ [ int(item) for item in
Hi,
Is there a way to apply multiple actions within one list comprehension?
i.e. instead of
a = []
for i in x:
i.pop(3)
g = [ int(item) for item in i]
a.append(g)
Is there any guides to this (possibly obtuse) tool?
Regards,
Liam Clarke
PS I can see how nested list comprehensio
At 07:03 AM 1/13/2005, Blake Winton wrote:
What about "x === item"
Perhaps we should propose an extension to Python:
Assignment Statement: name = [[name] = ] ... expression-list. The absence
of a name would create an anonymous variable just as lambda creates
anonymous functions.
Reminds me of a
Blake Winton wrote:
Kent Johnson wrote:
If you mean for j to be a list of foobar(item) then use
j=[foobar(item) for item in x]
The first part of the list comp can be any valid expression.
Does that mean that there are invalid expressions? I'd enjoy seeing
an example.
I suppose if it's an expressio
Kent Johnson wrote:
If you mean for j to be a list of foobar(item) then use
j=[foobar(item) for item in x]
The first part of the list comp can be any valid expression.
Does that mean that there are invalid expressions? I'd enjoy seeing an
example.
I suppose if it's an expression, it must be valid,
On Jan 13, 2005, at 04:13, Bob Gailer wrote:
I like Kent's response.
foobar(item)/0 is a "valid" expression. It fits the grammar of
expressions. The fact that it raises an exception does not make it an
invalid expression.
Consider foobar(item)/xyz. It is valid. If xyz == 0 then it will also
rai
At 07:05 PM 1/12/2005, Kent Johnson wrote:
I suppose if it's an expression, it must be valid, eh? Otherwise it's
something else.
At 06:41 PM 1/12/2005, Max Noel wrote:
On Jan 13, 2005, at 01:13, Bob Gailer wrote:
At 04:48 PM 1/12/2005, Kent Johnson wrote:
If you mean for j to be a list of foobar(i
I suppose if it's an expression, it must be valid, eh? Otherwise it's something
else.
Bob Gailer wrote:
At 04:48 PM 1/12/2005, Kent Johnson wrote:
If you mean for j to be a list of foobar(item) then use
j=[foobar(item) for item in x]
The first part of the list comp can be any valid expression.
Do
On Jan 13, 2005, at 01:13, Bob Gailer wrote:
At 04:48 PM 1/12/2005, Kent Johnson wrote:
If you mean for j to be a list of foobar(item) then use
j=[foobar(item) for item in x]
The first part of the list comp can be any valid expression.
Does that mean that there are invalid expressions? I'd enjoy se
At 04:48 PM 1/12/2005, Kent Johnson wrote:
If you mean for j to be a list of foobar(item) then use
j=[foobar(item) for item in x]
The first part of the list comp can be any valid expression.
Does that mean that there are invalid expressions? I'd enjoy seeing an
example.
Bob Gailer
mailto:[EMAIL PR
Aah, thank you both - I knew there was a way to do it.
Regards,
Liam Clarke
PS John - another Kiwi, seems to be a lot of NZers involved in Python
& Python projects. Is it the No. 8 wire freedom of Python? ; )
On Wed, 12 Jan 2005 18:48:39 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote:
> If you
If you mean for j to be a list of foobar(item) then use
j=[foobar(item) for item in x]
The first part of the list comp can be any valid expression.
Kent
Liam Clarke wrote:
Hi,
Am I able to achieve something like this -
def foobar();
# stuff
return
x=[1,1000]
for j=foobar(item) for item in x
Quoting Liam Clarke <[EMAIL PROTECTED]>:
> As a comprehension, if you get what I mean... Can I build a for loop
> with a function in for x in x part?
>
> Ack. Having difficulty summing it up properly.
I'm not sure exactly what you mean, so my answer is "probably".
>>> from math import sin
>>> a
Hi,
Am I able to achieve something like this -
def foobar();
# stuff
return
x=[1,1000]
for j=foobar(item) for item in x:
As a comprehension, if you get what I mean... Can I build a for loop
with a function in for x in x part?
Ack. Having difficulty summing it up properly.
--
'There
56 matches
Mail list logo