Re: Binary search tree

2007-11-13 Thread Scott Sandeman-Allen
On 11/13/07, Terry Reedy ([EMAIL PROTECTED]) wrote:


>"Scott SA" <[EMAIL PROTECTED]> wrote in message 
>news:[EMAIL PROTECTED]
>| On 11/12/07, Scott SA ([EMAIL PROTECTED]) wrote:
>| I decided to test the speeds of the four methods:
>|
>|set_example
>|s = set()
>|for url in urls:
>|if not url in s:
>|s.add(url)
>
>How is that different in result from

As mentioned in my earlier post, I'm fairly new to Python so many options are 
unknown to me (even then, there are often new ideas or approaches even for 
seasoned coders, I'm not looking forward to the days when I stop learning ;-).

>set_example2
>   s = set(urls)

Well, that's pretty sweet. Thanks for the heads-up on that!

>which would be much faster,  faster, I would expect, than

Please see below, it is the 'set2' result

>|dict_example
>|d = {}
>|for url in urls:
>|if url in d:
>|d[url] = 1

Note: 
There was an erorr in this, it was missing a 'not'
so it should have been:

   dict_example
   d = {}
   for url in urls:
   if not url in d:
   d[url] = 1

>|Starting tests with 50 simulated URLs run 3 times.
>|
>|'set' example
>|run time: 0.5505 seconds
>|'dict' example
>|run time: 0.2521 seconds

Starting tests with 50 simulated URLs run 3 times.

'set' example
run time: 0.8626 seconds
5000 unique URLs
'set2' example
run time: 0.4896 seconds
5000 unique URLs
'dict' example
run time: 0.4296 seconds
5000 unique URLs
'setdefault' example
run time: 0.9723 seconds
5000 unique URLs


Interestingly, the 'dict' method is still the champ for the simulations I 
created. Of course a different ratio of duplication within the source list 
could have an effect on performance, size of list (and I'm sure other 
environmental circumstances) would affect mileage.


Since my earlier posts, I found and re-read the original post:

>I have to get list of URLs one by one and to find the
>URLs that I have more than one time(can't be more than
>twice).

My re-interpretation of his needs were that there could be "no more than two" 
URL's. This means to me that not only did he require the unique 'set' but also 
needed to _count_ URL hits and subsequently process any overages.

>From my testing, the following _seems_ to be the best performer:

def dictcount_example(urls):
d = {}
for url in urls:
if url in d:
d[url] += 1
if d[url] > 2:
proc_overage(url) # handle overage
else:
d[url] = 1
return d

Without the 'if' statement (I added it for functional completeness), it 
performed as follows:

Starting tests with 50 simulated URLs run 3 times.

'dictcount' example
run time: 1.1556 seconds
5000 unique URLs



... Curiosity got me going, so I reduced the numbers of redundancies from 100 
to 5 and the unique URLs to 100,000. The results are:

Starting tests with 50 simulated URLs run 3 times.

'set' example
run time: 1.1986 seconds
10 unique URLs
'set2' example
run time: 0.5986 seconds
10 unique URLs
'dict' example
run time: 0.8676 seconds
10 unique URLs
'dictcount' example
run time: 1.3631 seconds
10 unique URLs


So, the set() functionality in Python appears better with smaller amm'ts of 
redundancy. Still, evaluating 1/2 mil. URLs in sub-second timeframes is a 
respectable, in my opinion, pace. Esp. when one considers the call is _one_ 
line!

Scaled to 2,000,000 URLs total and 1,000,000 unique URLs, the timings are 
interesting:

Starting tests with 200 simulated URLs run 3 times.

'set' example
run time: 7.9292 seconds
100 unique URLs
'set2' example
run time: 4.6351 seconds
100 unique URLs
'dict' example
 

Re: Photo gallery software

2008-05-01 Thread Scott Sandeman-Allen
On 5/1/08, Jumping Arne ([EMAIL PROTECTED]) wrote:

>I've searching for some software that would allow me to present my photos on 
>the web (I'm not interested a software that generates static pages that I 
>upload) and there are quite a few, see for example 
>, but I 
>haven't managed to find one that I like - Gallery 2 is close.
>
>So I've started to see if there is one that is based python (PHP isn't really 
>"my language") but when I search on Google almost the only thing I find are 
>photo galleries of snakes (to be honest I didn't know that people were *that* 
>interested in pythons).
>
>Do any anyone know if there exists photo gallery software written in Python?
>
>I've found
>
>

I've been working with Photologue for a while with some nice results.


It is a Django project 
,

It includes support for tagging:
 

It easily allows configuration of different image sizes and integrates with 
generic templates providing gallery and detail view support. 

HTH

Scott
--
http://mail.python.org/mailman/listinfo/python-list