Re: [Tutor] List comprehension question

2010-11-08 Thread Steven D'Aprano
Richard D. Moores wrote: So this version of my function uses a generator, range(), no? def proper_divisors(n): sum_ = 0 for x in range(1,n): if n % x == 0: sum_ += x return sum_ I'm going to be pedantic here... but to quote the Middleman, specificity is the so

Re: [Tutor] List comprehension question

2010-11-08 Thread Alan Gauld
"Steven D'Aprano" wrote I'm going to be pedantic here... but to quote the Middleman, specificity is the soul of all good communication. Be pedantic! :-) I really liked the explanation although I already sort of knew most of it. But there were a few nuggets in there I'd missed, like range()

Re: [Tutor] List comprehension question

2010-11-08 Thread Stefan Behnel
Alan Gauld, 08.11.2010 17:28: "Steven D'Aprano" wrote def proper_divisors(n): return sum(x for x in range(1, int(math.sqrt(n))) if n%x == 0) Why use math.sqrt() instead of just using the ** operator? return sum(x for x in range(1, int(n**0.5)) if n%x == 0) I'd have expected ** to be sign

Re: [Tutor] List comprehension question

2010-11-08 Thread Stefan Behnel
Hugo Arts, 08.11.2010 00:53: On Mon, Nov 8, 2010 at 12:36 AM, Richard D. Moores wrote: def proper_divisors(n): """ Return the sum of the proper divisors of positive integer n """ return sum([x for x in range(1,n) if int(n/x) == n/x]) The list comprehension is this function i

Re: [Tutor] List comprehension question

2010-11-08 Thread Alan Gauld
"Stefan Behnel" wrote Why use math.sqrt() instead of just using the ** operator? return sum(x for x in range(1, int(n**0.5)) if n%x == 0) Since this operation is only evaluated once in the whole runtime of the loop, I think readability beats the likely very tiny performance difference here

Re: [Tutor] List comprehension question

2010-11-08 Thread Alan Gauld
"Stefan Behnel" wrote On another note, getting rid of the list comprehension and using a generator expression will be even faster, since you won't have to build the list. I gave this suggestion a try. It is true for me when run in CPython 3.2: However, it is no longer true when I run the

[Tutor] Too different 2.6 vs 2.7?

2010-11-08 Thread Jorge Biquez
Hello all. Newbie question. Are there really BIG differences between version 2.6 and 2.7? Under my ubuntu configuration I can not install version 2.7, searching the why, but the version 2.6 is maintained and installed by the ubuntu software center. As a newby , trying to learn all the fe

Re: [Tutor] Too different 2.6 vs 2.7?

2010-11-08 Thread Karim
Hello Jorge, I have Ubuntu 10.04 LTS and get the same issue. I installed 2.7 version manually in another place using -prefix option. It works as long as you are pointing to the correct bin (python2.7) and the local lib/ installation (PYTHONPATH) from python 2.7. Regards Karim On 11/08/2010 09:

Re: [Tutor] Too different 2.6 vs 2.7?

2010-11-08 Thread Emile van Sebille
On 11/8/2010 12:44 PM Jorge Biquez said... Hello all. Newbie question. Are there really BIG differences between version 2.6 and 2.7? No, however there is quite a lot of info at http://docs.python.org/dev/whatsnew/2.7.html that details the changes, mostly 3.x features/bug-fixes back-ported to

Re: [Tutor] Too different 2.6 vs 2.7?

2010-11-08 Thread python
Jorge, Python 2.7 supports an updated version of the Tkinter GUI framework with support for native themes (ttk). This makes it possible to create professional looking user interfaces without having to install a separate GUI framework like wxPython or pyQt. Malcolm

Re: [Tutor] List comprehension question

2010-11-08 Thread Steven D'Aprano
Alan Gauld wrote: "Steven D'Aprano" wrote I'm going to be pedantic here... but to quote the Middleman, specificity is the soul of all good communication. Be pedantic! :-) I really liked the explanation although I already sort of knew most of it. But there were a few nuggets in there I'd mis

Re: [Tutor] Server

2010-11-08 Thread Chris King
On 11/5/2010 8:10 PM, Alan Gauld wrote: "Chris King" wrote If you are using Windows, turn off the built-in firewall. That's what fixed my problems. ~Corey also, it is on the same network, so the server shouldn't be a problem I think Corey means the firewall on your PC if you have one.

Re: [Tutor] Too different 2.6 vs 2.7?

2010-11-08 Thread Jorge Biquez
Hello all. So I guess the best is to have version 2.7 working. Thanks to all for the comments. Jorge Biquez At 03:14 p.m. 08/11/2010, pyt...@bdurham.com wrote: Jorge, Python 2.7 supports an updated version of the Tkinter GUI framework with support for native themes (ttk). This makes it possib

Re: [Tutor] List comprehension question

2010-11-08 Thread Steven D'Aprano
Stefan Behnel wrote: Hugo Arts, 08.11.2010 00:53: [...] On another note, getting rid of the list comprehension and using a generator expression will be even faster, since you won't have to build the list. I gave this suggestion a try. It is true for me when run in CPython 3.2: [...] However

[Tutor] Commercial or Famous Applicattions.?

2010-11-08 Thread Jorge Biquez
Hello all. Newbie question. Sorry. Can you mention applications/systems/solutions made with Python that are well known and used by public in general? ANd that maybe we do not know they are done with Python? I had a talk with a friend, "PHP-Only-Fan", and he said (you know the schema of thos

[Tutor] Columnar Transposition Cipher question

2010-11-08 Thread Natalie Kristine T. Castillo
Hi, I need help on how exactly to solve this: To send secret messages you and your partner have decided to use the columnar function you have written to perform columnar transposition cipher for this course. You have received the ciphertext EXLYHILOSHOOAETU from your friend. You two decide

Re: [Tutor] Too different 2.6 vs 2.7?

2010-11-08 Thread Terry Carroll
On Mon, 8 Nov 2010, Jorge Biquez wrote: Are there really BIG differences between version 2.6 and 2.7? I'm in a similar boat. I use Ubuntu 10.04 aw well as Windows XP, Vista and 7. I keep to similar levels just to avoid confusion and at present run Python 2.6 on all systems. If I had an u

Re: [Tutor] Server

2010-11-08 Thread Alan Gauld
"Chris King" wrote I think Corey means the firewall on your PC if you have one. It could be blocking outgoing traffic to uncommon port numbers or somesuch. The firewall pops up and I click allow. It has nothing to do with the firewall at all. Did you find any other errors at all? OK, de

Re: [Tutor] Too different 2.6 vs 2.7?

2010-11-08 Thread Alan Gauld
"Jorge Biquez" wrote Are there really BIG differences between version 2.6 and 2.7? No. As a newby , trying to learn all the features of all the libraries. That will take you a long time. Better to use it writing software IMHO. Learn the libraries you need as you need them. If you need

Re: [Tutor] Commercial or Famous Applicattions.?

2010-11-08 Thread Alan Gauld
"Jorge Biquez" wrote Can you mention applications/systems/solutions made with Python that are well known and used by public in general? ANd that maybe we do not know they are done with Python? The Python web site has an advocacy section, you will find several success stories there. HTH,

Re: [Tutor] Commercial or Famous Applicattions.?

2010-11-08 Thread Luke Paireepinart
just off the top of my head... NASA uses it. Lots of games use Python as their game logic/scripting language (how many use PHP? probably approaching 0. LUA is more popular than Python but Python is much more popular than PHP). The first ever bittorrent client (the official one) was written in P

Re: [Tutor] Columnar Transposition Cipher question

2010-11-08 Thread Luke Paireepinart
On Mon, Nov 8, 2010 at 5:28 PM, Natalie Kristine T. Castillo wrote: > Hi, I need help on how exactly to solve this: That's nice. > > To send secret messages you and your partner have decided to use the > columnar function you have written to perform columnar transposition cipher > for this course

Re: [Tutor] Server

2010-11-08 Thread Luke Paireepinart
On Mon, Nov 8, 2010 at 3:53 PM, Chris King wrote: >  On 11/5/2010 8:10 PM, Alan Gauld wrote: >> >> "Chris King" wrote >> If you are using Windows, turn off the built-in firewall. That's what fixed my problems. ~Corey >> >>> also, it is on the same network, so the server shouldn't b

Re: [Tutor] Commercial or Famous Applicattions.?

2010-11-08 Thread Walter Prins
Hi Jorge, Have a look at this page: http://www.python.org/about/quotes/ A few choice points to maybe make him think: 1.) Python is one of the top 3 languages at Google. (Where is PHP?...) 2.) Python can be used for GUI apps and has bindings for several GUI widget sets. (PHP?) 3.) Python can be

Re: [Tutor] Server

2010-11-08 Thread Chris King
On 11/8/2010 8:20 PM, Alan Gauld wrote: "Chris King" wrote I think Corey means the firewall on your PC if you have one. It could be blocking outgoing traffic to uncommon port numbers or somesuch. The firewall pops up and I click allow. It has nothing to do with the firewall at all. Did yo

Re: [Tutor] Columnar Transposition Cipher question

2010-11-08 Thread Wayne Werner
On Mon, Nov 8, 2010 at 5:28 PM, Natalie Kristine T. Castillo < ncasti...@umail.ucsb.edu> wrote: > Hi, I need help on how exactly to solve this: > > To send secret messages you and your partner have decided to use the > columnar function you have written to perform columnar transposition cipher > f

Re: [Tutor] Networking

2010-11-08 Thread Chris King
On 10/14/2010 9:28 PM, James Mills wrote: On Fri, Oct 15, 2010 at 11:22 AM, chris wrote: But what if I want it to serve one client, go to another and then go back. How does that work? You do some I/O multi-plexing or multi-processing/threading. You might want to do some reading on this. che

[Tutor] query result set

2010-11-08 Thread Shawn Matlock
I am able to successfully query a MySQL database using zxJDBC but the result set seems odd to me. It returns the following: [(u'envDB', u'systest2'), (u'envDir', u'st2'), (u'envCellName', u'Systest2Cell'), (u'envFrontEnd', u'systest2FrontEnd'), (u'envTag', u'system_test2')] Why is there a "u"

Re: [Tutor] Columnar Transposition Cipher question

2010-11-08 Thread Luke Pettit
I can suggest that the X should probably be a "D" you may want to check this with your tutor Although as a python noob I don't have the foggiest on how to do this in python, but will keep this for an exercise for if, and when I do. On paper it's pretty simple once you Wikipedia it. On 9 November 2

Re: [Tutor] Columnar Transposition Cipher question

2010-11-08 Thread Steven D'Aprano
On Mon, Nov 08, 2010 at 03:28:44PM -0800, Natalie Kristine T. Castillo wrote: > Hi, I need help on how exactly to solve this: > > To send secret messages you and your partner have decided to use the > columnar function you have written to perform columnar transposition > cipher for this course. You

Re: [Tutor] query result set

2010-11-08 Thread Steven D'Aprano
On Mon, Nov 08, 2010 at 05:58:36PM -0800, Shawn Matlock wrote: > I am able to successfully query a MySQL database using zxJDBC but the result > set seems odd to me. It returns the following: > > [(u'envDB', u'systest2'), (u'envDir', u'st2'), (u'envCellName', > u'Systest2Cell'), (u'envFrontEnd',

Re: [Tutor] List comprehension question

2010-11-08 Thread Richard D. Moores
On Mon, Nov 8, 2010 at 03:43, Steven D'Aprano wrote: > Richard D. Moores wrote: > Coming back to your function: > > def proper_divisors(n): >    sum_ = 0 >    for x in range(1,n): >        if n % x == 0: >            sum_ += x >    return sum_ > > > we can write that much more simply: > > def pro

Re: [Tutor] List comprehension question

2010-11-08 Thread Stefan Behnel
Richard D. Moores, 09.11.2010 06:31: On Mon, Nov 8, 2010 at 03:43, Steven D'Aprano wrote: Richard D. Moores wrote: Coming back to your function: def proper_divisors(n): sum_ = 0 for x in range(1,n): if n % x == 0: sum_ += x return sum_ we can write that much

Re: [Tutor] List comprehension question

2010-11-08 Thread Richard D. Moores
On Mon, Nov 8, 2010 at 21:31, Richard D. Moores wrote: > That sqrt(n) works for speeding up the finding of primes, but here we > want to use int(n/2) (and why didn't I think of that?), which results > in about a 2x speedup. See . NO! Use int(n/2)+1 . I'll

Re: [Tutor] List comprehension question

2010-11-08 Thread Richard D. Moores
On Mon, Nov 8, 2010 at 22:47, Richard D. Moores wrote: > On Mon, Nov 8, 2010 at 21:31, Richard D. Moores wrote: > >> That sqrt(n) works for speeding up the finding of primes, but here we >> want to use int(n/2) (and why didn't I think of that?), which results >> in about a 2x speedup. See