Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Ian Witham
On 10/12/07, Dick Moores <[EMAIL PROTECTED]> wrote: > > Please see the code and it's output here: > > > > I'm attempting to eliminate the elements (strings) of lstA that are > not well-formed in that they contain at least one character that is > not i

Re: [Tutor] slice lists and slicing syntax questions

2007-10-12 Thread Alan Gauld
<[EMAIL PROTECTED]> wrote > in matrix oriented languages like R, Octave / Matlab, and NumPy, > vectors, > lists, and matrices support slice lists of arbitrary indices. Python is a general purpose language and not matrix oriented. In fact it doesn't have native support for a matrix as such only t

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Alan Gauld
"Terry Carroll" <[EMAIL PROTECTED]> wrote > It took me a while to get list comprehensions. It's one of those > things > that suddenly snaps into place and you're suddenly comfortable with. Me too and I still don't like the syntax. its the [x for x in... bit at the start that reads badly for

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Terry Carroll
On Fri, 12 Oct 2007, Kent Johnson wrote: > Dick Moores wrote: > > > I'm just not comfortable with list comprehensions yet, > > Hmm, too bad. I use list comps and generator expressions constantly. It took me a while to get list comprehensions. It's one of those things that suddenly snaps into p

[Tutor] Help with packages and namespaces please

2007-10-12 Thread Andrew Wu
Hi all, I'm new to the list and relatively new to python, and very new to the use and creation of packages. Let's say I have these files in one directory: PrintBase.py PrintHello.py PrintBye.py PrintBase defines a very simple base class PrintBase, whose __init__ method initializes a member to a

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Kent Johnson
jim stockford wrote: > > On Oct 12, 2007, at 11:48 AM, Kent Johnson wrote: > >> If all you want to do is copy the list, then >>lstB = lstA[:] >> is fine, or you can use >>lstB = list(lstA) > > why choose one over the other? is there a performance > or other difference? The timeit module

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread jim stockford
On Oct 12, 2007, at 11:48 AM, Kent Johnson wrote: > If all you want to do is copy the list, then >lstB = lstA[:] > is fine, or you can use >lstB = list(lstA) why choose one over the other? is there a performance or other difference? ___ Tutor

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Kent Johnson
Dick Moores wrote: > At 12:34 AM 10/12/2007, Alan Gauld wrote: >> lstB = lstA[:] # a full slice creates a copy >> >> But thats not an efficient approach if you have a big list, the >> best route is to build a new list, preferably using a list >> comprehension. > > Alan, here's a test I made up.

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Dick Moores
At 11:29 AM 10/12/2007, Alan Gauld wrote: >"Dick Moores" <[EMAIL PROTECTED]> wrote > > >>But thats not an efficient approach if you have a big list, the > >>best route is to build a new list, preferably using a list > >>comprehension. > > > > Alan, here's a test I made up. It doesn't show your cont

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote >>But thats not an efficient approach if you have a big list, the >>best route is to build a new list, preferably using a list >>comprehension. > > Alan, here's a test I made up. It doesn't show your contention is > correct, but I imagine you or someone else

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Dick Moores
At 10:55 AM 10/12/2007, Kent Johnson wrote: >Dick Moores wrote: >>BTW is Kent's Korner still going at your SIG? Can we expect some >>more of these gems to appear soon on < >>http://personalpages.tds.net/~kent37/kk/>? > >Yes, it's a regular monthly feature of the meeting. I missed last >month but

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Kent Johnson
Dick Moores wrote: > BTW is Kent's Korner still going at your SIG? Can we expect some more of > these gems to appear soon on < http://personalpages.tds.net/~kent37/kk/>? Yes, it's a regular monthly feature of the meeting. I missed last month but there should be another one in a few weeks. The me

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Dick Moores
At 07:53 AM 10/12/2007, you wrote: Dick Moores wrote: Terrific, Kent. I promise I'll use 'em whenever I can. And I'll also try again to understand generators: < http://docs.python.org/tut/node11.html#SECTION0011100 >. But I'll begin with the section just before that, on iterators:

[Tutor] slice lists and slicing syntax questions

2007-10-12 Thread gregg
Hello Python Tutor! I have been using Python for years now, in all kinds of environments, but I don't really understand the restrictions on slicing. As described in http://jtauber.com/blog/2005/08/16/python_slice_questions/ and http://mail.python.org/pipermail/python-list/2006-February/368291.ht

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Kent Johnson
Dick Moores wrote: > Terrific, Kent. I promise I'll use 'em whenever I can. And I'll also > try again to understand generators: > . > But I'll begin with the section just before that, on iterators: >

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Kent Johnson
Dick Moores wrote: > Terrific, Kent. I promise I'll use 'em whenever I can. And I'll also > try again to understand generators: > . > But I'll begin with the section just before that, on iterators: >

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Dick Moores
At 05:35 AM 10/12/2007, Kent Johnson wrote: >Dick Moores wrote: >>At 03:41 AM 10/12/2007, Kent Johnson wrote: >>> finalList = [ word for word in lstA if all(c in astr for c in word) ] >>I'm just not comfortable with list comprehensions yet, > >Hmm, too bad. I use list comps and generator expressi

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Dick Moores
At 12:34 AM 10/12/2007, Alan Gauld wrote: >lstB = lstA[:] # a full slice creates a copy > >But thats not an efficient approach if you have a big list, the >best route is to build a new list, preferably using a list >comprehension. Alan, here's a test I made up. It doesn't show your contention is

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Kent Johnson
Dick Moores wrote: > At 03:41 AM 10/12/2007, Kent Johnson wrote: >> finalList = [ word for word in lstA if all(c in astr for c in word) ] > > I'm just not comfortable with list comprehensions yet, Hmm, too bad. I use list comps and generator expressions constantly. > but I see that > although

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Dick Moores
At 03:41 AM 10/12/2007, Kent Johnson wrote: >Aditya Lal wrote: >>finalList = [ word for word in lstA if wellformed(word) ] > >or do everything in one statement: > finalList = [ word for word in lstA if all(c in astr for c in word) ] I'm just not comfortable with list comprehensions yet, but I se

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Kent Johnson
Aditya Lal wrote: > finalList = [ word for word in lstA if wellformed(word) ] or do everything in one statement: finalList = [ word for word in lstA if all(c in astr for c in word) ] Note to Dick: You don't have to convert word to a list before iterating it: wordWithCommas = list(word)

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Aditya Lal
w.r.t. prob 2, there is no break/continue in the code that you have given. I added the "break" statement after you remove the word from lstB and code does seems to work for me. if word in lstB: lstB.remove(word) print print "Removed",

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Dick Moores
At 10:53 PM 10/11/2007, Dick Moores wrote: >Please see the code and it's output here: > > > >I'm attempting to eliminate the elements (strings) of lstA that are >not well-formed in that they contain at least one character that is >not in the string ast

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Dick Moores
At 12:18 AM 10/12/2007, Aditya Lal wrote: >lstB = lstA[:] Thanks! I'd completely forgotten how to copy a list. Dick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote > Well, if deleting from the same list I'm traversing is the problem, > why doesn't inserting the line > lstB = lstA > > and deleting from lstB clear it up? The output is exactly the same. You are not copying the list you are just making a second name refer

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Aditya Lal
lstB = lstA The above just points lstB to lstA and *does not* create a copy. If you do not understand "pointers", think of lstB an alias of lstA. If you want to create a copy you need to explicitly do it. lstB = [] for word in lstA : lstB.append(word) or shortcut lstB = lstA[:] So, even tho

Re: [Tutor] 2 problems in a small script

2007-10-12 Thread Dick Moores
At 11:25 PM 10/11/2007, Aditya Lal wrote: >Hi Dick, > >You are deleting from the SAME list that you are traversing. This >results in problems. Aditya, Well, if deleting from the same list I'm traversing is the problem, why doesn't inserting the line lstB = lstA and deleting from lstB clear it