[Tutor] Fwd: Problem Euler 26

2008-06-30 Thread Andre Engels
On Sun, Jun 29, 2008 at 10:34 PM, kinuthiA muchanE <[EMAIL PROTECTED]> wrote: > Er... er, that does not exactly work as expected but it narrows the > search to only 3 candidates because of the inclusion of the zero: > > (28, '035714286') > (38, '026315789') > (81, '012345679') > > For 28, the d

Re: [Tutor] String concatenation too slow

2008-06-30 Thread Chris Fuller
You could try creating a list of strings, and then using a ''.join(list) to concatenate, but you are probably going to be best off using the cStringIO module (http://docs.python.org/lib/module-cStringIO.html). Try timing all three and see how they compare when joining lots of strings. The leng

Re: [Tutor] String concatenation too slow

2008-06-30 Thread Shrutarshi Basu
My bad, should have included some code. Here's the function which does the grunt work. self.axiom is a string, where each character gets replaced by its counterpart from self.rules. output then goes back to the calling function. That's the end of one generation of the string. The next generation ha

Re: [Tutor] String concatenation too slow

2008-06-30 Thread wesley chun
> I've been > using string concatenation to read through the string, and then create > the new one based on a dictionary lookup. However it becomes very slow > once the string gets very long (several thousand characters). [...] > I was wondering if there might be a > faster alternative to strin

[Tutor] String concatenation too slow

2008-06-30 Thread Shrutarshi Basu
I'm working on a program to create Lindenmayer systems. These systems depend on heavy string rewriting to form complex patterns.I've been using string concatenation to read through the string, and then create the new one based on a dictionary lookup. However it becomes very slow once the string get

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Martin Walsh
Hi Norman, Norman Khine wrote: > > for brain in brains: > x = getattr(brain, horizontal) > x = string.join(x, '' ) > y = getattr(brain, vertical) > y = string.join(y, '' ) > if x and y and (x, y) in table: > table

Re: [Tutor] Deleting specified files using a python program...help with code?]

2008-06-30 Thread David
Alan Gauld wrote: "David" <[EMAIL PROTECTED]> wrote dir_input = raw_input('Enter dir: ') win_trace = ['*.ini', '*.db'] files_removed = 0 for root, dirs, files in os.walk(dir_input): for trace in win_trace: win_trace_path = os.path.join(root, trace) for filename in glob.glob(wi

Re: [Tutor] Deleting specified files using a python program...help with code?]

2008-06-30 Thread Alan Gauld
"David" <[EMAIL PROTECTED]> wrote dir_input = raw_input('Enter dir: ') win_trace = ['*.ini', '*.db'] files_removed = 0 for root, dirs, files in os.walk(dir_input): for trace in win_trace: win_trace_path = os.path.join(root, trace) for filename in glob.glob(win_trace_path):

Re: [Tutor] Is "var = None" in Python equivalent to "Set var

2008-06-30 Thread Alan Gauld
"John Fouhy" <[EMAIL PROTECTED]> wrote (I don't want to criticise VB programmers because I am not one. "Follow the local conventions" is generally always a good rule of programming) I think this is a key point. I'm no VB expert but I do have to read it from time to time. VB programmers tend t

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Alan Gauld
"Jerry Hill" <[EMAIL PROTECTED]> wrote You can do it with slice assignment too: a = [1, 2, 3, 4] a[1:3] = [[7, 8]] a [1, [7, 8], 4] Now, which way is better? The answer depends on context. If, conceptually, you are removing two elements from a list, then adding a new element which is itse

Re: [Tutor] Is "var = None" in Python equivalent to "Set var

2008-06-30 Thread Tony Cappellini
This thread got a bit off track > >>but in Python these statements are unnecessary. > > What happened to "Explicit is better than implicit"? > Regarding the "original poster" contrasting VB with Python setting someObject = None is perfectly fine in Python, and a good analogy between the langu

Re: [Tutor] Is "var = None" in Python equivalent to "Set var

2008-06-30 Thread John Fouhy
On 01/07/2008, Tony Cappellini <[EMAIL PROTECTED]> wrote: > In VB6 ( I have not worked with VB.NET), objects are set to Nothing when > they go out of scope, yet there is a fair amount lot of code out there where > objects are explicitly set to Nothing. This is a pretty common practice in > VB land.

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Douglas Drumond
Thanks, Ryan, for detailed explanation; I'm learning Python now, too, so I don't know exactly how stuff works. []'s Douglas On Mon, Jun 30, 2008 at 18:33, Lie Ryan <[EMAIL PROTECTED]> wrote: >> You can do it with slice assignment too: >> >>> a = [1, 2, 3, 4] >> >>> a[1:3] = [[7, 8]] >> >>> a

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Lie Ryan
> You can do it with slice assignment too: > >>> a = [1, 2, 3, 4] > >>> a[1:3] = [[7, 8]] > >>> a > [1, [7, 8], 4] >  > Now, which way is better? The answer depends on context. The best > way to write it is in the manner that it makes the most sense to > someone reading your program (including

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Jerry Hill
On Mon, Jun 30, 2008 at 4:47 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > Show me a better way? You can do it with slice assignment too: >>> a = [1, 2, 3, 4] >>> a[1:3] = [[7, 8]] >>> a [1, [7, 8], 4] Now, which way is better? The answer depends on context. The best way to write it is in the ma

Re: [Tutor] Deleting specified files using a python program...help with code?]

2008-06-30 Thread David
I am learning python from books and this mailing list. I used the suggestions to come up with this; #!/usr/bin/python # Filename : new_remove-file.py import os import sys import glob dir_input = raw_input('Enter dir: ') win_trace = ['*.ini', '*.db'] files_removed = 0 for root, dirs, files in os.

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Dick Moores
At 01:39 PM 6/30/2008, Dick Moores wrote: At 11:01 PM 6/29/2008, wesley chun wrote: > > e.g. can you predict the result of the following operations without trying it? > > > > a = [1, 2, 3, 4] > > a[1:3] = [7, 8] > > print a > >  [1, 7, 8, 4]   Whew! >  (I really wasn't positive that it shouldn't

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Dick Moores
At 11:01 PM 6/29/2008, wesley chun wrote: > > e.g. can you predict the result of the following operations without trying it? > > > > a = [1, 2, 3, 4] > > a[1:3] = [7, 8] > > print a > >  [1, 7, 8, 4]   Whew! >  (I really wasn't positive that it shouldn't be [1, [7, 8], 4] !) good job dick! of cou

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Norman Khine
Hi, Sorry, but this did not work. I have done this, which returns the values I want (sort of) for brain in brains: x = getattr(brain, horizontal) if isinstance(x, list): for item in x: x = item else:

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Alan Gauld
"Norman Khine" <[EMAIL PROTECTED]> wrote but when I run this, I get the following error on the line: if x and y and (x, y) in table: TypeError: list objects are unhashable Please post the entire error. The tiny bit you posted was not overly helpful, usually the stacjk trace contains the ac

Re: [Tutor] destroying windows

2008-06-30 Thread Alan Gauld
"Jim Morcombe" <[EMAIL PROTECTED]> wrote If the user selects an option, then I want to destroy that window and then display a second window. In turn, the user can select an option to change back to the first window and I want to destroy that window and then display the first again. You proba

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Cédric Lucantis
Le Monday 30 June 2008 21:31:35, vous avez écrit : > Thanks, > but where do i replace the x with tuple(x) > Whenever x is hashed, ie used as a key in a dictionary. You said you have: > >> table[(x, y)] += 1 > >> where: > >> > >> x = ['airlines-scheduled', 'airport-car-parking']

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Norman Khine
Thanks, but where do i replace the x with tuple(x) Norman Cédric Lucantis wrote: Le Monday 30 June 2008 20:55:36 Norman Khine, vous avez écrit : Hello, I would like to count list items but am not 100% sure how to do it. Here is what I have so far: for brain in brains:

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Cédric Lucantis
Le Monday 30 June 2008 20:55:36 Norman Khine, vous avez écrit : > Hello, > > I would like to count list items but am not 100% sure how to do it. > > Here is what I have so far: > > for brain in brains: > x = getattr(brain, horizontal) > y = getattr(brain, vertical

[Tutor] list objects are unhashable

2008-06-30 Thread Norman Khine
Hello, I would like to count list items but am not 100% sure how to do it. Here is what I have so far: for brain in brains: x = getattr(brain, horizontal) y = getattr(brain, vertical) if x and y and (x, y) in table: table[(x, y)] += 1

Re: [Tutor] Is "var = None" in Python equivalent to "Set var

2008-06-30 Thread Tony Cappellini
Message: 5 Date: Mon, 30 Jun 2008 11:49:59 +0200 From: "Andre Engels" <[EMAIL PROTECTED]> Subject: Re: [Tutor] Is "var = None" in Python equivalent to "Set var = Nothing"in VB? To: Kelie <[EMAIL PROTECTED]> Cc: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text

Re: [Tutor] destroying windows

2008-06-30 Thread Cédric Lucantis
Le Monday 30 June 2008 14:47:39 Jim Morcombe, vous avez écrit : > I want to have a program that uses Tkinter to display a window. > If the user selects an option, then I want to destroy that window and > then display a second window. > In turn, the user can select an option to change back to the fi

Re: [Tutor] need help; save web data

2008-06-30 Thread W W
On Sun, Jun 29, 2008 at 2:28 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > Note that this may be a violation of the Google Scholar terms of > service; I know it is a violation to automatically collect normal > Google search results, and IIRC Google takes some steps to make it > difficult as well.

Re: [Tutor] Deleting specified files using a python program...help with code?

2008-06-30 Thread Cédric Lucantis
Le Monday 30 June 2008 16:17:45 Saad Javed, vous avez écrit : > Here's the working code for my problem. But i tried it to post 'No > files found' in case no specified files are found. It doesn't do that. > Just simply exits. > > dir_input = raw_input('Enter dir: ') > > win_trace = ['*.ini', '*.db']

Re: [Tutor] Deleting specified files using a python program...help with code?

2008-06-30 Thread Saad Javed
Here's the working code for my problem. But i tried it to post 'No files found' in case no specified files are found. It doesn't do that. Just simply exits. dir_input = raw_input('Enter dir: ') win_trace = ['*.ini', '*.db'] for root, dirs, files in os.walk(dir_input): for trace in win_tr

[Tutor] destroying windows

2008-06-30 Thread Jim Morcombe
I want to have a program that uses Tkinter to display a window. If the user selects an option, then I want to destroy that window and then display a second window. In turn, the user can select an option to change back to the first window and I want to destroy that window and then display the fir

Re: [Tutor] Is "var = None" in Python equivalent to "Set var

2008-06-30 Thread Kent Johnson
On Mon, Jun 30, 2008 at 12:53 AM, wesley chun <[EMAIL PROTECTED]> wrote: >> As I understand it there are no cases where obj==None and obj is None >> will give different results (which is not true for == vs is in >> general), so is there any practical difference? Maybe you save a >> handful of c

Re: [Tutor] Is "var = None" in Python equivalent to "Set var = Nothing"in VB?

2008-06-30 Thread Andre Engels
On Mon, Jun 30, 2008 at 11:26 AM, Kelie <[EMAIL PROTECTED]> wrote: > wesley chun gmail.com> writes: >> one question i'd like to ask is, in what context is such a line part >> of your code? altho alan is correct in that syntactically, they're >> very similar, i'm wondering what you're using it for.

Re: [Tutor] Is "var = None" in Python equivalent to "Set var = Nothing"in VB?

2008-06-30 Thread wesley chun
> Thanks for your reply (also thanks to others who replied). I was trying to > translate a VBA sample in this page http://tinyurl.com/3hvj3j to python. The > VBA > sample has a line "Set objDbx = Nothing". kelie, thanks for your reply... it helps clear things up -- i didn't think i was going to

Re: [Tutor] Is "var = None" in Python equivalent to "Set var = Nothing"in VB?

2008-06-30 Thread Kelie
wesley chun gmail.com> writes: > one question i'd like to ask is, in what context is such a line part > of your code? altho alan is correct in that syntactically, they're > very similar, i'm wondering what you're using it for. Wesley, Thanks for your reply (also thanks to others who replied). I