Re: How should I handle socket receiving?

2011-03-11 Thread n00m
I'm abs not sure but maybe you'll need to put
each client into separate thread; like this

def Client_func(s2, cn):
 while 1:
 data = cn.recv(4096)
 if not data:
 s2.shutdown(1)
 return
 s2.sendall(data)



cn, addr = s1.accept()
s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s2.connect((the_server_host, the_server_port))
thread.start_new_thread(Client_func, (s2, cn,))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just finished reading of "What’s New In Python 3.0"

2011-03-11 Thread n00m
Fitzgerald had been an alcoholic since his college days, and became
notorious during the 1920s for his extraordinarily heavy drinking,
leaving him in poor health by the late 1930s. According to Zelda's
biographer, Nancy Milford, Scott claimed that he had contracted
tuberculosis, but Milford dismisses it as a pretext to cover his
drinking problems. However, Fitzgerald scholar Matthew J. Bruccoli
contends that Fitzgerald did in fact have recurring tuberculosis, and
Nancy Milford reports that Fitzgerald biographer Arthur Mizener said
that Scott suffered a mild attack of tuberculosis in 1919, and in 1929
he had "what proved to be a tubercular hemorrhage". It has been said
that the hemorrhage was caused by bleeding from esophageal varices.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just finished reading of "What’s New In Python 3.0"

2011-03-10 Thread n00m
On Mar 11, 8:35 am, Grigory Javadyan 
wrote:
> > Moreover I'm often able to keep in mind 2 (or more) opposite ideas or
> > opinions of mine.
>
> """
> To know and not to know, to be conscious of complete truthfulness
> while telling carefully constructed lies, to hold simultaneously two
> opinions which cancelled out, knowing them to be contradictory and
> believing in both of them, to use logic against logic, to repudiate
> morality while laying claim to it, to believe that democracy was
> impossible and that the Party was the guardian of democracy...
> """



The test of a first-rate intelligence is the ability to hold two
opposed
ideas in the mind at the same time, and still retain the ability to
function.


 --- F. Scott
Fitzgerald


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


Re: Just finished reading of "What’s New In Python 3.0"

2011-03-10 Thread n00m
On Mar 11, 7:45 am, Terry Reedy  wrote:
> On 3/10/2011 8:58 PM, n00m wrote:
>
> >http://docs.python.org/py3k/whatsnew/3.0.html
>
> > What's the fuss abt it? Imo all is ***OK*** with 3k (in the parts I
> > understand).
> > I even liked print as a function **more** than print as a stmt
>
> > Now I think that Py3k is better than all prev pythons and cobras.
>
> I agree ;-). Now read What's New for 3.1 and 3.2 and load and use 3.2
> with numberous fixes and improvements to doc and code. 3.3 will be
> better yet.
>
> --
> Terry Jan Reedy

I'm still keeping opened in FF tab "What’s New In Python 3.0" :)
5 cups of coffee. None wiser. I wonder why am I so unluckily stupid?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just finished reading of "What’s New In Python 3.0"

2011-03-10 Thread n00m
On Mar 11, 4:05 am, alex23  wrote:
> On Mar 11, 11:58 am, n00m  wrote:
>
> >http://docs.python.org/py3k/whatsnew/3.0.html
>
> > What's the fuss abt it? Imo all is ***OK*** with 3k (in the parts I
> > understand).
> > I even liked print as a function **more** than print as a stmt
>
> > Now I think that Py3k is better than all prev pythons and cobras.
>
> So are you a troll or just incredibly fickle? It's barely been two
> weeks since your proud proclamation that Python 2.5 was BEST PYTHON
> EVAR and that "Python 3 is a tempor. lapse of reason":
>
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/76e...

The latter ("incredibly fickle").
Moreover I'm often able to keep in mind 2 (or more) opposite ideas or
opinions of mine.
But I am not a troll by any means. It's out of my interests.
-- 
http://mail.python.org/mailman/listinfo/python-list


Just finished reading of "What’s New In Python 3.0"

2011-03-10 Thread n00m
http://docs.python.org/py3k/whatsnew/3.0.html

What's the fuss abt it? Imo all is ***OK*** with 3k (in the parts I
understand).
I even liked print as a function **more** than print as a stmt

Now I think that Py3k is better than all prev pythons and cobras.

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


Madam Bovary

2011-03-10 Thread n00m
Just let you know: I'm on her (Emma's) side.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-07 Thread n00m
@all and just in case.
Also see my TiRG project (since 2011-01-31):
http://sourceforge.net/projects/tirg/
It's for detecting and localizing textareas in raster graphics.
Among its files there is a python script -- absolutely working.
Enjoy to do with it whatever you like -- it's my public domain.

And again and this theme is a rich field for speculating about,
over "What on the earth is the text?" question.
Is 50 in a row letters 'o' some text or is it just a part of
some fancy Indian ornament? And so on, etc.

PS
Don't confuse it with OCR. It's 2 different beasts.
===
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-07 Thread n00m
So, my current very strict definition of similarity is:

---
2 pics are similar if my script gives for them value < 20%,
otherwise the pics are not similar.
---

It is left to study possible transitivity of similarity.


==
LOL
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-07 Thread n00m
On Mar 7, 2:54 pm, Grigory Javadyan 
wrote:
> Just admit that your algorithm doesn't work that well already :-)
> Or give a solid formal definition of "similarity" and prove that your
> algo works with that definition.
>
> On Mon, Mar 7, 2011 at 4:22 PM, n00m  wrote:
>
> > In short,
> > the notion of similarity can be speculated about just endlessly.
>
>


Remind me this piece of humor:

One man entered a lift cabin at the 1st floor,
lift goes to the3rd floor, opens and ... it's empty!
Physicist, Chemist and Mathematician were asked:
what happened to the man?

Physicist: he was squashed to the floor by acceleration!

Chemist: he was vaporized by some acid gases!

Mathematician: hmm... Let's call a lift *empty* if
there is inside of it no more than *1* man.

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


Re: ImSim: Image Similarity

2011-03-07 Thread n00m
On Mar 6, 7:54 pm, n00m  wrote:
> If someone will encounter 2 apparently unrelated pics
> but for which ImSim gives value of their mutual diff.
> *** less than 20% *** please emailed them to me.

Never mind, people.
I've found such a pair of images in my .zipped project.
It's "sky1.jpg" and "lake1.jpg", with sim. value < 15%.

sky1.jpg

sky1.jpg0.00
sky2.jpg0.77
   lake1.jpg   14.28<-
  bears2.jpg   23.29
  bears3.jpg   26.60
  roses2.jpg   29.41
  roses1.jpg   31.36
 ff1.jpg   33.47
  bears1.jpg   36.60
 ff2.jpg   39.52
  water1.jpg   40.11

But funny thing takes place.
At first thought it's a false-positive: some modern South East
Asian town and a lake somewhere in Russia, more than 100 years
ago. Nothing similar in them?

On both pics we see:
-- a lot of water on foreground;
-- a lot of blue sky at sunny mid-day;
-- a bit of light white clouds in the sky;

In short,
the notion of similarity can be speculated about just endlessly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I'm happy with Python 2.5

2011-03-06 Thread n00m
http://www.spoj.pl/forum/viewtopic.php?f=20&t=8264
That's all what I meant to say in here.
User numerix (German?) knows ropes of Python miles
far better than e.g. me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-06 Thread n00m

As for "proper" quoting: I read/post to this group via my web-browser.
And for me everything looks OK. I don't even quite understand what
exactly
do you mean by your remark. I'm not a facebookie/forumish/twitterish
thing.
Btw I don't know what is the twitter. I don't need it, neither to know
nor
to use it. Oh... Pres. Medvedev knows what is the twitter and uses it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I'm happy with Python 2.5

2011-03-06 Thread n00m
PS
The winner (just a schoolboy) of IOI 2009 lives in my town,
not very far from my house. I'm proud to have such a neibour.
His account on spoj: http://www.spoj.pl/users/tourist/
Of course he's also registered on many other online judge systems,
incl. www.topcoder.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-06 Thread n00m
On Mar 6, 10:17 pm, n00m  wrote:
> On Mar 6, 8:55 pm, John Bokma  wrote:
>
>
>
> > n00m  writes:
> > >http://www.nga.gov/search/index.shtm
> > >http://deyoung.famsf.org/search-collections
> > > etc
> > > Seems they all offer search only by keywords and this kind.
> > > What about to submit e.g. roses2.jpg (copy) and to find its
> > > original? Assume we don't know its author neither its title
>
> > Title: TinEye, author:http://ideeinc.com/
> > Search:http://www.tineye.com/
>
> > Example:
> >  http://www.tineye.com/search/2b3305135fa4c59311ed58b41da5d07f213e4d47/
>
> > Notice how it finds modified images.
>
> > --
> > John Bokma                                                               j3b
>
> > Blog:http://johnbokma.com/  Facebook:http://www.facebook.com/j.j.j.bokma
> >     Freelance Perl & Python Development:http://castleamber.com/
>
> It's for kids.
> Such trifles can easily be cracked by e.g. Jorgen Grahn's algo (see
> his message)


Even his algo will be an overhead.
Comparing meta-data/EXIF of image files will be enough in 99% cases.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I'm happy with Python 2.5

2011-03-06 Thread n00m
On Mar 6, 7:25 pm, Michael Torrie  wrote:
> On 02/27/2011 06:57 AM, n00m wrote:
>
> > Steve, see a list of accepted langs there, in bottom dropdown:
> >http://www.spoj.pl/submit/There *was* Python 2.6.
> > Then admins shifted back to 2.5. People vote by their legs.
>
> rr, is that you?

Are you asking me?
If so, my account there is http://www.spoj.pl/users/zzz/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-06 Thread n00m
On Mar 6, 8:55 pm, John Bokma  wrote:
> n00m  writes:
> >http://www.nga.gov/search/index.shtm
> >http://deyoung.famsf.org/search-collections
> > etc
> > Seems they all offer search only by keywords and this kind.
> > What about to submit e.g. roses2.jpg (copy) and to find its
> > original? Assume we don't know its author neither its title
>
> Title: TinEye, author:http://ideeinc.com/
> Search:http://www.tineye.com/
>
> Example:
>  http://www.tineye.com/search/2b3305135fa4c59311ed58b41da5d07f213e4d47/
>
> Notice how it finds modified images.
>
> --
> John Bokma                                                               j3b
>
> Blog:http://johnbokma.com/   Facebook:http://www.facebook.com/j.j.j.bokma
>     Freelance Perl & Python Development:http://castleamber.com/


It's for kids.
Such trifles can easily be cracked by e.g. Jorgen Grahn's algo (see
his message)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-06 Thread n00m
Obviously if we'd use it in practice (in a web-museum ?)
all pic's matrices should be precalculated only once and
stored in a table with fourty fields v00 ... v93 like:

---
pic_title  v00v01v02... v93
---
bears2.jpg1234   4534   8922... 333
...
...
---

Then SQL query will look like this:

select top 3 pic_title from table
order by
abs(v00 - w[0][0]) +
abs(v01 - w[0][1]) +
... +
abs(v93 - w[9][3])

here w[][] is the matrix of a newly-entering picture.


P.S.
If someone will encounter 2 apparently unrelated pics
but for which ImSim gives value of their mutual diff.
*** less than 20% *** please emailed them to me.

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


Re: ImSim: Image Similarity

2011-03-05 Thread n00m
http://www.nga.gov/search/index.shtm
http://deyoung.famsf.org/search-collections
etc
Seems they all offer search only by keywords and this kind.
What about to submit e.g. roses2.jpg (copy) and to find its
original? Assume we don't know its author neither its title
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-05 Thread n00m
On Mar 6, 6:10 am, Mel  wrote:
> n00m wrote:
> > As for using color info...
> > my current strong opinion is: the colors must be forgot for good.
> > Paradoxically but "profound" elaboration and detailization can/will
> > spoil/undermine the whole thing. Just my current imo.
>
> Yeah.  I guess including color info cubes the complexity of the answer.  
> Might be too complicated to know what to do with an answer like that.
>
>         Mel.

Uhmm, Mel. Totally agree with you.
+
I included "roses1.jpg" & "roses2.jpg" on purpose:
the 1st one is a painting by Abbott Handerson Thayer,
the 2nd is its copy by some obscure Russian painter.
But it's of course a creative & revamped copy.

In strict sense they are 2 different images (look at their colors etc)
, on the other hand they are closely related to each other.
Plus, we can't tell *in principle* what is original and what is copy
what colors are "right/good" and what colors are "wrong/bad"

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


Re: ImSim: Image Similarity

2011-03-05 Thread n00m

PS

For some reason they don't update the link to the last version.

It's _20110306, here: http://sourceforge.net/projects/imsim/files/

I use Python 2.5 & PIL for Python 2.5

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


Re: ImSim: Image Similarity

2011-03-05 Thread n00m
>
> Is it better than this?
> - scale each image to 100x100
> - go black&white in such a way that half the pixels are black
> - XOR the images and count the mismatches


It's *much* better but I'm not *much* about to prove it.



> I'm sure there are better,
> well-known algorithms.


The best well-known algorithm is to hire a man with good eyesight
for to do the job of comparing, ranking and selecting the pictures.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImSim: Image Similarity

2011-03-05 Thread n00m
On Mar 5, 7:10 pm, Mel  wrote:
> n00m wrote:
>
> > I uploaded a new version of the subject with a
> > VERY MINOR correction in it. Namely, in line #55:
>
> >     print '%12s %7.2f' % (db[k][1], db[k][0] / 3600.0,)
>
> > instead of
>
> >     print '%12s %7.2f' % (db[k][1], db[k][0] * 0.001,)
>
> > I.e. I normalized it to base = 100.
> > Now the values of similarity can't be greater than 100
> > and can be treated as some "regular" percents (%%).
>
> > Also, due to this change, the *empirical* threshold of
> > "system alarmity" moved down from "number 70" to "20%".
>
> >   bears2.jpg
> > 
> >   bears2.jpg    0.00
> >   bears3.jpg   15.37
> >   bears1.jpg   19.13
> >     sky1.jpg   23.29
> >     sky2.jpg   23.45
> >      ff1.jpg   25.37
> >    lake1.jpg   26.43
> >   water1.jpg   26.93
> >      ff2.jpg   28.43
> >   roses1.jpg   31.95
> >   roses2.jpg   36.12
>
> I'd like to see a *lot* more structure in there, with modularization, so the
> internal functions could be used from another program.  Once I'd figured out
> what it was doing, I had this:
>
> from PIL import Image
> from PIL import ImageStat
>
> def row_column_histograms (file_name):
>     '''Reduce the image to a 5x5 square of b/w brightness levels 0..3
>     Return two brightness histograms across Y and X
>     packed into a 10-item list of 4-item histograms.'''
>     im = Image.open (file_name)
>     im = im.convert ('L')       # convert to 8-bit b/w
>     w, h = 300, 300
>     im = im.resize ((w, h))
>     imst = ImageStat.Stat (im)
>     sr = imst.mean[0]   # average pixel level in layer 0
>     sr_low, sr_mid, sr_high = (sr*2)/3, sr, (sr*4)/3
>     def foo (t):
>         if t < sr_low: return 0
>         if t < sr_mid: return 1
>         if t < sr_high: return 2
>         return 3
>     im = im.point (foo) # reduce to brightness levels 0..3
>     yhist = [[0]*4 for i in xrange(5)]
>     xhist = [[0]*4 for i in xrange(5)]
>     for y in xrange (h):
>         for x in xrange (w):
>             k = im.getpixel ((x, y))
>             yhist[y / 60][k] += 1
>             xhist[x / 60][k] += 1
>     return yhist + xhist
>
> def difference_ranks (test_histogram, sample_histograms):
>     '''Return a list of difference ranks between the test histograms and
> each of the samples.'''
>     result = [0]*len (sample_histograms)
>     for k, s in enumerate (sample_histograms):  # for each image
>         for i in xrange(10):    # for each histogram slot
>             for j in xrange(4): # for each brightness level
>                 result[k] += abs (s[i][j] - test_histogram[i][j])      
>     return result
>
> if __name__ == '__main__':
>     import getopt, sys
>     opts, args = getopt.getopt (sys.argv[1:], '', [])
>     if not args:
>         args = [
>             'bears1.jpg',
>             'bears2.jpg',
>             'bears3.jpg',
>             'roses1.jpg',
>             'roses2.jpg',
>             'ff1.jpg',
>             'ff2.jpg',
>             'sky1.jpg',
>             'sky2.jpg',
>             'water1.jpg',
>             'lake1.jpg',
>         ]
>         test_pic = 'bears2.jpg'
>     else:
>         test_pic, args = args[0], args[1:]
>
>     z = [row_column_histograms (a) for a in args]
>     test_z = row_column_histograms (test_pic)
>
>     file_ranks = zip (difference_ranks (test_z, z), args)      
>     file_ranks.sort()
>
>     print '%12s' % (test_pic,)
>     print ''
>     for r in file_ranks:
>         print '%12s %7.2f' % (r[1], r[0] / 3600.0,)
>
> (omitting a few comments that wrapped around.)  The test-case still agrees
> with your archived version:
>
> mwilson@tecumseth:~/sandbox/im_sim$ python image_rank.py bears2.jpg *.jpg
>   bears2.jpg
> 
>   bears2.jpg    0.00
>   bears3.jpg   15.37
>   bears1.jpg   19.20
>     sky1.jpg   23.20
>     sky2.jpg   23.37
>      ff1.jpg   25.30
>    lake1.jpg   26.38
>   water1.jpg   26.98
>      ff2.jpg   28.43
>   roses1.jpg   32.01
>
> I'd vaguely wanted to do something like this for a while, but I never dug
> far enough into PIL to even get started.  An additional kind of ranking that
> takes colour into account would also be good -- that's the first one I never
> did.
>
>         Cheers,         Mel.


Very nice, Mel.

As for using color info...
my current strong opinion is: the colors must be forgot for good.
Paradoxically but "profound" elaboration and detailization can/will
spoil/undermine the whole thing. Just my current imo.


===
Vitali

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


Re: ImSim: Image Similarity

2011-03-05 Thread n00m

I uploaded a new version of the subject with a
VERY MINOR correction in it. Namely, in line #55:

print '%12s %7.2f' % (db[k][1], db[k][0] / 3600.0,)

instead of

print '%12s %7.2f' % (db[k][1], db[k][0] * 0.001,)

I.e. I normalized it to base = 100.
Now the values of similarity can't be greater than 100
and can be treated as some "regular" percents (%%).

Also, due to this change, the *empirical* threshold of
"system alarmity" moved down from "number 70" to "20%".

  bears2.jpg

  bears2.jpg0.00
  bears3.jpg   15.37
  bears1.jpg   19.13
sky1.jpg   23.29
sky2.jpg   23.45
 ff1.jpg   25.37
   lake1.jpg   26.43
  water1.jpg   26.93
 ff2.jpg   28.43
  roses1.jpg   31.95
  roses2.jpg   36.12

Done!

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


ImSim: Image Similarity

2011-03-04 Thread n00m
Let me present my newborn project (in Python) ImSim:

http://sourceforge.net/projects/imsim/

Its README.txt:
-
ImSim is a python script for finding the most similar pic(s) to
a given one among a set/list/db of your pics.
The script is very short and very easy to follow and understand.
Its sample output looks like this:

  bears2.jpg

  bears2.jpg0.00
  bears3.jpg   55.33
  bears1.jpg   68.87
sky1.jpg   83.84
sky2.jpg   84.41
 ff1.jpg   91.35
   lake1.jpg   95.14
  water1.jpg   96.94
 ff2.jpg  102.36
  roses1.jpg  115.02
  roses2.jpg  130.02

Done!

The *less* numeric value -- the *more similar* this pic is to the
tested pic. If this value > 70 almost for sure these pictures are
absolutely different (from totally different domains, so to speak).

What is "similarity" and how can/could/should it be estimated this
point I'm leaving for your consideration/contemplation/arguing etc.

Several sample pics (*.jpg) are included into .zip.
And of course the stuff requires PIL (Python Imaging Library), see:
Home-page: http://www.pythonware.com/products/pil
Download-URL: http://effbot.org/zone/pil-changes-116.htm

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


Re: OT: Code Examples

2011-02-28 Thread n00m
On Feb 28, 6:03 pm, Fred Marshall 
wrote:
> I'm interested in developing Python-based programs, including an
> engineering app. ... re-writing from Fortran and C versions.  One of the
> objectives would to be make reasonable use of the available structure
> (objects, etc.).  So, I'd like to read a couple of good, simple
> scientific-oriented programs that do that kind of thing.
>
> Looking for links, etc.
>
> Fred

The best place for you to start: http://numpy.scipy.org/

Numpy manual: http://www.tramy.us/numpybook.pdf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I'm happy with Python 2.5

2011-02-27 Thread n00m
http://www.spoj.pl/problems/TMUL/

Python's "print a * b" gets Time Limit Exceeded.

=
PHP's code
=
fscanf(STDIN, "%d\n", &$tcs);
while ($tcs--) {
fscanf(STDIN, "%s %s\n", &$n, &$m);
echo bcmul($n, $m, 0)."\n";
}
=
does it in 4.8s
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I'm happy with Python 2.5

2011-02-27 Thread n00m
On Feb 27, 3:58 pm, Grigory Javadyan 
wrote:
> what the hell does that have to do with anything
>
> On Sun, Feb 27, 2011 at 5:34 PM, n00m  wrote:
> > Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
> > (Intel)] on win32
>
> > and Idon't move neither up nor down from it (the best & the fastest
> > version)
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
>

Am I turmoiling your wishful thinking?
You may nourish it till the end of time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I'm happy with Python 2.5

2011-02-27 Thread n00m
Steve, see a list of accepted langs there, in bottom dropdown:
http://www.spoj.pl/submit/ There *was* Python 2.6.
Then admins shifted back to 2.5. People vote by their legs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I'm happy with Python 2.5

2011-02-27 Thread n00m
Python 3 is a tempor. lapse of reason.
Just my an intuitive sensation, nothing objective in it.
-- 
http://mail.python.org/mailman/listinfo/python-list


I'm happy with Python 2.5

2011-02-27 Thread n00m
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win32

and Idon't move neither up nor down from it (the best & the fastest
version)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why this difference?

2011-02-24 Thread n00m
@nn, @Terry Reedy:

Good reading. Thanks. In fact now the case is closed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why this difference?

2011-02-24 Thread n00m
> Don't rely on it.

Hmm I never was about to rely on it.
Simply sorta my academic curiosity.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why this difference?

2011-02-24 Thread n00m
The 1st "False" is not surprising for me.
It's the 2nd "True" is a bit hmmm... ok, it doesn't matter
==
Have a nice day!
-- 
http://mail.python.org/mailman/listinfo/python-list


Why this difference?

2011-02-24 Thread n00m
file my.txt:
===
0 beb
1 qwe
2 asd
3 hyu
4 zed
5 asd
6 oth
=


py script:
===
import sys

sys.stdin = open('88.txt', 'r')
t = sys.stdin.readlines()
t = map(lambda rec: rec.split(), t)
print t
print t[2][1] == t[5][1]
print t[2][1] is t[5][1]
print '=='
a = 'asd'
b = 'asd'
print a is b


output:
===
[['0', 'beb'], ['1', 'qwe'], ['2', 'asd'], ['3', 'hyu'], ['4', 'zed'],
['5', 'as
d'], ['6', 'oth']]
True
False
==
True



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


Re: Running Scripts vs Interactive mode

2011-02-23 Thread n00m
Add into each your *.py script and as the very last line this:
raw_input('Press any key to exit...')

Or, even better, I'd recommend this free Python Editor:
http://pythonide.stani.be/
SPE IDE - Stani's Python Editor
Free python IDE for Windows,Mac & Linux with UML,PyChecker,Debugger,
GUI design,Blender & more

A superb thing, imo.

But firstly download and install python package *wxPython*:
wxPython2.8-win32-unicode-2.8.11.0-py25.exe

SPE Editor needs it to work properly.

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


Re: Python leaks in cyclic garbage collection

2011-02-21 Thread n00m
> Wild guess:
> maybe when python exits they are called but sys.stdout has already been 
> closed and nothing gets written on it anymore.

Certainly NOT.


class Foo():
def __init__(self):
self.b = Bar(self)
def __del__(self):
print "Free Foo"

class Bar():
def __init__(self, f):
self.f = f
def __del__(self):
print "Free Bar"


f = Foo()
print f.b.f.b.f.b.f.b.f.b.f.b.f.b.f.b.f
print f.b.f.b.f.b.f.b.f.b.f.b.f.b.f.b.f.b



*Console output:***

<__main__.Foo instance at 0x00AF7328>
<__main__.Bar instance at 0x00AF7350>

D:\v3>

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


Re: Keeping track of the N largest values

2010-12-26 Thread n00m

from bisect import insort_left

K = 5
top = []
while 1:
x = input()
if len(top) < K:
insort_left(top, x)
elif x > top[0]:
del top[0]
insort_left(top, x)
print top


will be enough

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


Re: twenty years ago Guido created Python

2010-01-05 Thread n00m
Stick your English into your ass
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: twenty years ago Guido created Python

2010-01-04 Thread n00m
Ben, go away from here. With all your stupids sigs.
Do you think are you original?
You are a stupid animal.
Guido, Tim Peters, Raymond Hettinger are geniuis.
I don't know exactly Python mob. Maybe forgot someone.
You is only a source of depspise for them
You get your everymonth fucking 1000 e sitting here
whom are you teaching? This crowds of animals?
They and you you cant nothing
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: twenty years ago Guido created Python

2010-01-03 Thread n00m
Now tell me:
what ahat this mobs of yellow, africans, asiats, are doing in
Stockholm?
Do you think your govs let me in just to vist England, Norway? Never.
Its all conditionally. But the fact is. IS.
You roll our world into abyss of stupidity

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


Re: Any Swisses here?

2010-01-03 Thread n00m
What Imeant by what waht
try to solve e.g. http://acm.sgu.ru/problem.php?contest=0&problem=482
99% people here are 0 in this. They know this they know that, but they
can't nothing, they simply are sitting on this group and apraised
themselves But you can nothing
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: twenty years ago Guido created Python

2010-01-03 Thread n00m
i'm sobered up
Yes of course Guido and his lang is both superb things
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any Swisses here?

2010-01-02 Thread n00m
On Jan 3, 5:30 am, Steve Holden  wrote:
> Zhu Sha Zang wrote:
> >> [stuff and nonsense from a third party]
> > WTF?
>
> We do get the occasional bigot dropping in from time to time. Best to
> ignore them 'til they go away.
>
> regards
>  Steve
> --
> Steve Holden           +1 571 484 6266   +1 800 494 3119
> PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
> Holden Web LLC                http://www.holdenweb.com/
> UPCOMING EVENTS:        http://holdenweb.eventbrite.com/

And who are YOU?
What you achieved in the life?
For me you is nothing I recall only Kipling, Dickens, Newton
its your background. My backgroung is the best rockets
-- 
http://mail.python.org/mailman/listinfo/python-list


Any Swisses here?

2010-01-02 Thread n00m
Congrats!
Your choice -- to ban building of muslim mosques -- is the only choice
to save our civililazation.
This yellow plague (incl. Chinese etc) must be eliminated from our
Planet,
They are very cunning critters, they can play on strings of
compassion,
but its riffraffs. What do you know about Russia? Who are yuo against
Russia?
Nothing. Dust. We are simply tired people.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Brent's variation of a factorization algorithm

2009-12-10 Thread n00m
On Dec 10, 2:59 am, Irmen de Jong  wrote:
> On 12/10/09 12:52 AM, n00m wrote:
>
> > On Dec 10, 1:11 am, Irmen de Jong  wrote:
> >> 9
> >> == 27 * 37037037
>
> >> What gives? Isn't this thing supposed to factor numbers into the product
> >> of two primes?
>
> >> -irmen
>
> > Only if you yield to it a SEMIprime =)
>
> A 'semiprime' being a product of 2 prime numbers, I suppose.
>
> >> 27 * 37037037
> > Now you can apply brent() to these numbers, and so on
>
> Right :)   I more or less expected it to do that by itself (didn't look
> at the algorithm)
>
> But you wrote that it might run indefinately if you feed it a prime
> number. There's no safeguard then against getting into an endless loop
> if you keep applying brent() to the factors it produces? Because in the
> end one or both factors will be prime...
>
> -irmen


Just to use e.g. Rabin-Miller's before supplying a number to brent()

> A 'semiprime' being a product of 2 prime numbers, I suppose.

Aha, exactly.
==
Also it's worthy to test a num is it a perfect square?
But all this is obvious trifles...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Brent's variation of a factorization algorithm

2009-12-10 Thread n00m
On Dec 10, 1:11 am, Irmen de Jong  wrote:
> 9
> == 27 * 37037037
>
> What gives? Isn't this thing supposed to factor numbers into the product
> of two primes?
>
> -irmen

Only if you yield to it a SEMIprime =)
> 27 * 37037037
Now you can apply brent() to these numbers, and so on
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Brent's variation of a factorization algorithm

2009-12-10 Thread n00m
PPS
The code was successfully tested e.g. here:
http://www.spoj.pl/ranks/FACT1/ (see my 2nd and 4th places).
They confused versions: the 2nd is in Python 2.5, not 2.6.2.
PPPS
Funnilly... almost only Python on the 1st page =)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Brent's variation of a factorization algorithm

2009-12-09 Thread n00m
Being an absolute dummy in Theory of Number
for me ***c'est fantastique*** that brent() works =)

PS
1.
Values of magic parameters c = 11 and m = 137
almost don't matter. Usually they choose c = 2
(what about to run brent() in parallel with different
values of "c" waiting for "n" is cracked?)

2.
Before calling brent() "n" should be tested for its
primality. If it is a prime brent(n) may freeze for good.

3.
> A better place to publish this code would be the Python Cookbook:

It requires a tedious registration etc.
Gabriel, don't you mind to publish the code there by yourself?
In the long run, it is an invention by Richard Brent (b.1946) =)
I just rewrote it to Python from a pseudo-code once available in
Wiki but which for some vague reason was later on removed from there.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to understand += better

2009-11-30 Thread n00m
> The first statement is creating a whole new list;

Yes but *imo* not quite exactly so.
We can't think of 2 lists as of absolutely independent
things.

... x = [[0]]
... id(x)
19330632
... id(x[0])
19316608
... z = x + [3]
... id(z)
19330312
... id(z[0])
19316608
...
... z[0] is x[0] # ?
True
... x[0][0] = 1
...
... z[0][0]
1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-30 Thread n00m
> Some sexually transmitted diseases make your genitals drip.

I suspected this :-) Eminem is a famous misogynist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can "self" crush itself?

2009-11-30 Thread n00m
Ok ok
Of course, it's a local name; -- just my silly slip.
And seems it belongs to no dict[]...
Just an internal volatile elf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can "self" crush itself?

2009-11-30 Thread n00m
> Why would you want to do that in the first place?

I don't know... :-)
As Schoepenhauer put it:
The man can do what he wants to do but he can't want to want
what he wants to do

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


Brent's variation of a factorization algorithm

2009-11-30 Thread n00m
Maybe someone'll make use of it:


def gcd(x, y):
if y == 0:
return x
return gcd(y, x % y)

def brent(n):
c = 11
y, r, q, m = 1, 1, 1, 137
while 1:
x = y
for i in range(1, r + 1):
y = (y * y + c) % n
k = 0
while 1:
ys = y
for i in range(1, min(m, r - k) + 1):
y = (y * y + c) % n
q = (q * abs(x - y)) % n
g = gcd(q, n)
k += m
if k >=r or g > 1:
break
r *= 2
if g > 1:
break
if g == n:
while 1:
ys = (ys * ys + c) % n
g = gcd(abs(x - ys), n)
if g > 1:
break
return g


while 1:
n = eval(raw_input())
g = brent(n)
print '==', g, '*', n / g



IDLE 1.2   No Subprocess 

1170999422783 * 10001
== 73 * 160426920921271
1170999422783 * 254885996264477
== 1170999422783 * 254885996264477
1170999422783 * 415841978209842084233328691123
== 1170999422783 * 415841978209842084233328691123
51539607551 * 80630964769
== 51539607551 * 80630964769
304250263527209 * 792606555396977
== 304250263527209 * 792606555396977
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Number of distinct substrings of a string [continuation]

2009-11-29 Thread n00m
On Nov 29, 11:43 pm, Bearophile  wrote:
> Anyway, you may try a pure-Python2.x 
> implementation:http://suffixtree.googlecode.com/files/suffixtree-0.1.py

Ouch, Bearie... 214 lines of code are there.
Ok.. I tested it.
Firstly I replaced all "print " with "pass##print "
(aiming to avoid intensive printing from inside of the code).

Then I left in its final part only building of suffix trees.

==
...
...
...

from time import time
t = time()

import sys
sys.stdin = open('D:/88.txt', 'rt')
f = sys.stdin.read().split()
sys.stdin.close()

z = open('D:/99.txt', 'wt')

for tc in range(int(f[0])):
s = f[tc + 1]
test_str = s + '$'
POSITIVE_INFINITY = len(test_str) - 1
suffix_tree = SuffixTree(test_str)
print >> z, 'len(s) =', len(s)

print >> z, 'time =', time() - t
z.close()


Output:

len(s) = 1000
len(s) = 1000
len(s) = 1
time = 0.64132425


0.64s > 0.48s (of my algo)
I.e. the code can't help in my very special and narrow case.

But of course it is worthy to be studied and memoized.
E.g.:
from huge string "s" we built its Suffix Tree.
Now we are given arbitrary string "ss".
Task: to find the largest its prefix occured in "s",
traversing its Suffix Tree.




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


Re: Number of distinct substrings of a string [continuation]

2009-11-29 Thread n00m
Tested both my codes against
a random string of length = 1.

===

from random import choice
s = ''
for i in xrange(1):
s += choice(('a','b','c','d','e','f'))

===

C++: ~0.28s
Python: ~0.48s

PS
I suspect that building of Suffix Tree would
be a big exec.time-consuming overhead
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Number of distinct substrings of a string [continuation]

2009-11-29 Thread n00m
http://en.wikipedia.org/wiki/Suffix_tree

Looks not very friendly appealing :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Number of distinct substrings of a string [continuation]

2009-11-29 Thread n00m
On Nov 29, 3:15 pm, Bearophile  wrote:
> Maybe in your C++ code there's something that can be improved, this is
> a 1:1 translation to D (V.1) language (using dlibs) and it's about 2.2
> times faster than the Psyco version:http://codepad.org/MQLj0ydB
> Using a smarter usage of memory (that is avoiding all or most memory
> allocations inside all loops), the performance difference will surely
> grow.

Very interesting. Thanks.
D code looks pretty neat. Btw D lang is among accepted langs there.
Even if Py by 4x *slower* -- it's still a perfect Ok for it (C# will
be
much (much) slower than Python).

Micro-optimizations.
Of course, the best optimization would be to implement Suffix Tree:
http://en.wikipedia.org/wiki/Trie
Currently I hardly understand/know/read/etc its core idea. My algo is
plainly stupid as soldier muddy boots.

My C++ code:


#include 
#include 
//#include 
//#include 
//#include 
#include 
#include 
#include 
#include 
using namespace std;

int main() {
clock_t start_time = clock();
freopen("88.txt", "rt", stdin);
freopen("99.txt", "wt", stdout);

int tcs;
string s;
cin >> tcs;
while (tcs-- > 0) {
cin >> s;
int n = s.size();
s = s + ' ';
vector< vector > a(128);
int ans = 0;
for (int i = n - 1; i >= 0; --i) {
int lev = 0;
for (int st = (int)a[s[i]].size() - 1; st >= 0; --st) {
int j = a[s[i]][st];
if (n - j <= lev) break;
if (s[j + lev] != s[i + lev]) continue;
if (s[j + lev / 2] != s[i + lev / 2]) continue;
int k = 0;
while (s[j + k] == s[i + k]) ++k;
if (k > lev) lev = k;
}
a[s[i]].push_back(i);
ans += n - i - lev;
}
cout << ans << endl;
}

cout << (clock() - start_time) / CLOCKS_PER_SEC << endl;

return 0;
}








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


Re: Number of distinct substrings of a string [continuation]

2009-11-29 Thread n00m
This worked out in 5.28s
Imo it's not that *much* slower
(of course, Psyco can't help here)
===

import itertools
def subs(s):
return len(set(itertools.chain(
s[i:j]
for i in xrange(len(s))
for j in xrange(i, len(s)+1 - 1


from time import time
t = time()

import sys
sys.stdin = open('D:/88.txt', 'rt')
f = sys.stdin.read().split()
sys.stdin.close()

z = open('D:/99.txt', 'wt')

for tc in range(int(f[0])):
s = f[tc + 1]
print >> z, subs(s)

print >> z, time() - t
z.close()

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


Re: Number of distinct substrings of a string [continuation]

2009-11-29 Thread n00m
My Py solution:

=

import psyco
psyco.full()

def foo(s):
n = len(s)
s = s + ' '
a = [[] for i in xrange(128)]
ans = 0
for i in xrange(n - 1, -1, -1):
lev = 0
for st in xrange(len(a[ord(s[i])]) - 1, -1, -1):
j = a[ord(s[i])][st]
if (n - j <= lev):
break
if (s[j + lev] != s[i + lev]):
continue
if (s[j + lev / 2] != s[i + lev / 2]):
continue
k = 0
while (s[j + k] == s[i + k]):
k += 1
if (k > lev):
lev = k
a[ord(s[i])] += [i]
ans += n - i - lev
return ans


from time import time
t = time()

import sys
sys.stdin = open('D:/88.txt', 'rt')
f = sys.stdin.read().split()
sys.stdin.close()

z = open('D:/99.txt', 'wt')

for tc in range(int(f[0])):
s = f[tc + 1]
print >> z, foo(s)

print >> z, time() - t
z.close()


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


Re: Python Programming Challenges for beginners?

2009-11-28 Thread n00m
PS
My straightforward C++ solution got TLE...

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

int main() {
//freopen("88.txt", "rt", stdin);
//freopen("99.txt", "wt", stdout);
int tcs;
string s;
cin >> tcs;
while (tcs-- > 0) {
cin >> s;
int n = s.size();
s = s + ' ';
vector< vector > a(256);
int ans = 0;
for (int i = n - 1; i >= 0; --i) {
int lev = 0;
vector p = a[s[i]];
vector q;
while (!p.empty()) {
q.clear();
++lev;
for (int j = 0; j < p.size(); ++j) {
if (s[p[j] + 1] == s[i + lev]) {
q.push_back(p[j] + 1);
}
}
p.swap(q);
}
a[s[i]].push_back(i);
ans += n - i - lev;
}
cout << ans << endl;
}

return 0;
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Programming Challenges for beginners?

2009-11-28 Thread n00m
On Nov 28, 8:24 pm, Lie Ryan  wrote:
> Now, this makes me interested. How efficient it would be when len(s) ==
> 1... might as well write it and see. Take back what I said, give me
> a minute...

... and you can check it here: http://www.spoj.pl/problems/DISUBSTR/
I see there only one (accepted) solution in Python:
http://www.spoj.pl/ranks/DISUBSTR/lang=PYTH%202.5
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Programming Challenges for beginners?

2009-11-27 Thread n00m
On Nov 27, 6:00 pm, Paul Rudin  wrote:
> efficiency ...

This is it!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Programming Challenges for beginners?

2009-11-27 Thread n00m
> abba
> bbaz> abbaz
> > ==
> > Answer: 11
>
> Answer: 13- Hide quoted text -


14 ! with '' (empty substring :-))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Programming Challenges for beginners?

2009-11-27 Thread n00m
On Nov 27, 1:22 pm, Jon Clements  wrote:
> Of course, if you take '~' literally (len(s) <= -10001) I reckon
> you've got way too many :)
>
> Jon.

Then better: len(s) < abs(~1)

PS It's a hard problem; so let's leave it alone
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Programming Challenges for beginners?

2009-11-27 Thread n00m
> You're missing some sub-strings.

Yes! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Programming Challenges for beginners?

2009-11-26 Thread n00m
On Nov 27, 5:24 am, astral orange <457r0...@gmail.com> wrote:
[skip]

How about the next problem:
you are given string "s" (len(s) <= ~1), in the string only
letters 'a'..'z'
Task: to count the number of all *different* substrings of "s"

Example:
s = 'abbaz'
Its different substrings are:
a
b
z
ab
bb
ba
az
abb
bba
baz
abbaz
==
Answer: 11
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can "self" crush itself?

2009-11-25 Thread n00m

aaah... globals()...
Then why "self" not in globals()?

class Moo:
cnt = 0
def __init__(self, x):
self.__class__.cnt += 1
if self.__class__.cnt < 3:
self.x = x
else:
print id(self)
for item in globals().items():
print item

f = Moo(1)
g = Moo(2)
h = Moo(3)


>>> = RESTART 
>>>
13407336
('g', <__main__.Moo instance at 0x00CC9260>)
('f', <__main__.Moo instance at 0x00CC9440>)
('__builtins__', )
('Moo', )
('__name__', '__main__')
('__doc__', None)
>>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can "self" crush itself?

2009-11-25 Thread n00m
> Or just raise an exception in __init__(),..

Then we are forced to handle this exception outside of class code.
It's Ok. Never mind.


Next thing.
I can't understand why we can get __name__, but not __dict__,
on the module level?


print __name__
print __dict__


>>> = RESTART 
>>>
__main__

Traceback (most recent call last):
  File "D:\Python25\zewrt.py", line 19, in 
print __dict__
NameError: name '__dict__' is not defined

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


Re: Can "self" crush itself?

2009-11-25 Thread n00m
Then how can we destroy the 3rd instance,
right after its creation and from inside
class Moo code?

class Moo:
cnt = 0
def __init__(self, x):
self.x = x
self.__class__.cnt += 1
if self.__class__.cnt > 2:
print id(self)
## 13406816
## in what dict is this ID?
## and can we delete it from there?

## ???


f = Moo(1)
g = Moo(2)
h = Moo(3)
print h

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


Re: Can "self" crush itself?

2009-11-24 Thread n00m

> Whatever you rebind ‘self’ to inside the function...


Seems you are right! Thanks, Ben, for the lesson :-)


class Moo:
cnt = 0
def __init__(self, x):
self.x = x
self.__class__.cnt += 1
if self.__class__.cnt > 2:
self.crush_me()
def crush_me(self):
print 'Will self be crushed?'
self = None
print self

f = Moo(1)
g = Moo(2)
h = Moo(3)
print '='
print h



Will self be crushed?
None
=
<__main__.Moo instance at 0x00CC9468>
-- 
http://mail.python.org/mailman/listinfo/python-list


Can "self" crush itself?

2009-11-24 Thread n00m
Why does "h" instance stay alive?

class Moo:
cnt = 0
def __init__(self, x):
self.x = x
self.__class__.cnt += 1
if self.__class__.cnt > 2:
self.crush_me()
def crush_me(self):
print 'Will self be crushed?'
self = None

f = Moo(1)
g = Moo(2)
h = Moo(3)

print f
print g
print h


=== RESTART 

Will self be crushed?
<__main__.Moo instance at 0x00CC9260>
<__main__.Moo instance at 0x00CC9468>
<__main__.Moo instance at 0x00CC94B8>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread n00m
> it's somewhat unnatural to say "too different xs"

Aha. Thanks.
PS
For years I thought that song's title "No Woman No Cry" by Bob Marley
means "No Woman -- No Cry". As if a man got rid of his woman and
stopped
crying, out of her bad behaviour etc.
It turned out to mean "No, woman,.. no cry..."

Or take "Drips" by Eminem. What on earth do the drips mean?

Album:  The Eminem Show
Song:   Drips

[Eminem] Obie.. yo
 [Trice] {*coughing*} I'm sick
[Eminem] Damn, you straight dog?

[Chorus]
That's why I ain't got no time
for these games and stupid tricks
or these bitches on my dick
That's how dudes be gettin sick
That's how dicks be gettin drips
Fallin victims to this shit...
...
...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread n00m
:-) Of course, by "too" I meant "too", as in "to much"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread n00m
Here "meaningful order" is:
if
elephant "a[i]" is smarter than elephant "a[j]"
then "i" must be strictly less than "j"

Of course, to the same effect we could sort them simply
by sizes, but then time of sorting would increase by ~
2 times -- due to decreasing of number of equally smart
things.

But here it does not matter -- for my initial question.
I like all above explanations. Especially that by Chris Rebert.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread n00m

> The second part of the compound if is backwards.  So if this is headed
> for production code, it better get fixed.
>
> DaveA

Not sure I'm understanding your remark.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread n00m
> Do you get the same magnitude difference
> if you make Vector a new-style class?

Yes (I mean "No"): new-style's much faster

And now it's elephants instead of vectors.
Def: an elephant is smarter than another one IIF
its size is strictly less but its IQ is strictly
greater

I.e. you can't compare (2, 8) to (20, 50)
or let count them as equally smart elephants.


class Elephant(object):
def __init__(self, size, iq):
self.size = size
self.iq = iq
def __cmp__(self, e):
if self.size < e.size and self.iq > e.iq:
return -1
if self.size > e.size and self.iq < e.iq:
return 1
return 0

def e_cmp(e1, e2):
if e1.size < e2.size and e1.iq > e2.iq:
return -1
if e1.size > e2.size and e1.iq < e2.iq:
return 1
return 0

from random import randint
from time import time

a = []
for i in xrange(20):
a.append(Elephant(randint(1, 5), randint(1, 5)))
b = a[:]
c = a[:]

print 'Sorting...'

t = time()
b.sort(cmp=e_cmp)
print time() - t

t = time()
c.sort()
print time() - t

print b == c



>>> = RESTART =
>>>
Sorting...
1.5626376
1.9536866
True
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting: too different times. Why?

2009-11-22 Thread n00m

I was expecting the 1st method would be *slower* than the 2nd one :-)
Or at least equal... Just random ("intuitive") expectations
-- 
http://mail.python.org/mailman/listinfo/python-list


Sorting: too different times. Why?

2009-11-22 Thread n00m
Any comment:

class Vector:
def __init__(self, x, y):
self.x = x
self.y = y
def __cmp__(self, v):
if self.x < v.x and self.y > v.y:
return -1
return 0

def v_cmp(v1, v2):
if v1.x < v2.x and v1.y > v2.y:
return -1
return 0

from random import randint
from time import time

a = []
for i in range(20):
a += [Vector(randint(0, 50), randint(0, 50))]
b = a[:]
c = a[:]

print 'Sorting...'

t = time()
b.sort(cmp=v_cmp)
print time() - t

t = time()
c.sort()
print time() - t

print b == c



>>> = RESTART ==
>>>
Sorting...
0.906000137329
6.57799983025
True

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


Re: What do I do now?

2009-10-13 Thread n00m

I'm going to develop further my py. script for
text detection and localization in raster images:
http://funkybee.narod.ru/

Slow Doe...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enormous Input and Output Test

2009-10-08 Thread n00m
N00m The Instigator... hahaha :-)
I always wish I was a producer, an entertainer,
an impressario, or even a souteneur (kidding).

Life is complex: it has both real and imaginary parts.
Some producer (Mr. Gomelsky) nicknamed Eric Clapton as
"Slow Hand", many years ago.
Gomel is my native town and apparently russian name
"Gomelsky" means "smb/smth belonging to Gomel".

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


Re: Enormous Input and Output Test

2009-10-08 Thread n00m
Congrats, Irmen.

PS
> so I think 7.5 seconds for the fastest ...

It's becoming crazy :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enormous Input and Output Test

2009-10-08 Thread n00m
numerix's solution was excelled by Steve C's one (8.78s):
http://www.spoj.pl/ranks/INOUTEST/lang=PYTH
I don't understand nothing.

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


Re: Enormous Input and Output Test

2009-10-06 Thread n00m
What happened to performance of ver.2.6.2 (vs ver.2.5.x)?

https://www.spoj.pl/forum/viewtopic.php?f=20&t=5949
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to sort a list of strings on a substring

2009-10-06 Thread n00m
Here you are:

LogList = [\
"inbound tcp office 192.168.0.125 inside 10.1.0.91 88",
"inbound tcp office 192.168.0.220 inside 10.1.0.31 2967",
"inbound udp lab 172.24.0.110 inside 10.1.0.6 161",
"inbound udp office 192.168.0.220 inside 10.1.0.13 53"]


LogList.sort(key=lambda x: x[x.index('1'):])

for item in LogList:
print item

===

inbound udp lab 172.24.0.110 inside 10.1.0.6 161
inbound tcp office 192.168.0.125 inside 10.1.0.91 88
inbound udp office 192.168.0.220 inside 10.1.0.13 53
inbound tcp office 192.168.0.220 inside 10.1.0.31 2967
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enormous Input and Output Test

2009-10-06 Thread n00m
> This takes 5 second on my machine using a file with 1,000,000 random...

Surely it will fail to pass time limit too
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enormous Input and Output Test

2009-10-06 Thread n00m
> 50-80%% of users from the 1st page in ranklist are
> super-extra-brilliant

#5 there: http://www.spoj.pl/users/tourist/
This 14 y.o. schoolboy won IOI 2009, in this August,
and he's about to get into Guiness' book as the youngest
winner for all the history of international olympiads on
informatics.
He lives at 20 minutes of walking from my house, -- it's
South East Belarus, near to Chernobyl (mutants?).
Hardly I'm able to do even 10% of what he can do, though
I'm older by 3 times than him.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to sort a list of strings on a substring

2009-10-05 Thread n00m
In my early teen, school years "Let It Be" by The Beatles sounded for
my
ears (incredibly clearly and obviously!) as "Lia Ri Pip".
In school I studied French, English only many years later.

My inner translation of "Here you are!" is smth like
"Catch it!", "Take it!", "Look at this!" etc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to sort a list of strings on a substring

2009-10-05 Thread n00m
English language is not my mother toung,
so I can't grasp many subtle nuances of it.
Maybe "here you are" means to me quite a
different thing than to you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to sort a list of strings on a substring

2009-10-05 Thread n00m
> No, that's incorrect. Try it with this data and you will see it fails:

Of course, you are right, but I think the topic-starter is smart
enough
to understand that I suggested only a hint, a sketch, a sample of how
to use "key=" with "lambda", not a ready-to-apply solution.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enormous Input and Output Test

2009-10-05 Thread n00m
Duncan Booth,

alas... still TLE:

2800839
2009-10-04 13:03:59
Q
Enormous Input and Output Test
time limit exceeded
-
88M
PYTH
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enormous Input and Output Test

2009-10-05 Thread n00m
> but unlike us, he's routinely under 11s.  Crazy.

No wonder!
50-80%% of users from the 1st page in ranklist are
super-extra-brilliant (young students) programmers.
They are winners of numerous competitions, national
and international olympiads on informatics, etc.
Some of them are/were even true wunderkinders.
E.g. Tomek Czajka from Poland (now he lives and works,
in some university, in America)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regex (?!..) problem

2009-10-04 Thread n00m
Why not check it simply by "count()"?

>>> s = '1234C156789'
>>> s.count('C1')
1
>>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enormous Input and Output Test

2009-10-04 Thread n00m
It can be not so "simple".
There can be multiple input files,
with *total* size ~30-50-80 MB.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enormous Input and Output Test

2009-10-04 Thread n00m
This time limits too:

=
import psyco
psyco.full()

import sys

def foo():
##sys.stdin = open('D:/1583.txt', 'rt')
a = sys.stdin.readlines()
a = a[1:int(a[0]) + 1]
for ai in a:
x, y = ai.split()
sys.stdout.write(str(int(x) * int(y)) + '\n')

foo()
=
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enormous Input and Output Test

2009-10-04 Thread n00m
PS
Yes, they support psyco since long time ago
(otherwise I'd get Compilitation Error verdict).
I used Psyco there many many times.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enormous Input and Output Test

2009-10-04 Thread n00m

I've given up :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enormous Input and Output Test

2009-10-03 Thread n00m
And this code time limits (no matter with or without Psyco):

import psyco
psyco.full()

import sys

def foo():
##sys.stdin = open('D:/1583.txt', 'rt')
sys.stdin.readline()
while 1:
try:
x, y = sys.stdin.readline().split()
sys.stdout.write(str(int(x) * int(y)) + '\n')
except:
break

foo()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enormous Input and Output Test

2009-10-03 Thread n00m

And *without* Psyco the above code gets TLE verdict...

A kind of mystery :(
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enormous Input and Output Test

2009-10-03 Thread n00m
> On my machine, the above code handles ~50MB in ~10sec.

Means their input > 40-50MB
2.
I just see: two guys did it in Python
and I feel myself curious "how on earth?".
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >