Re: [Tutor] List manipulation

2006-09-14 Thread Kent Johnson
Srinivas Iyyer wrote: Thank you Bob for your email. Sorry for the confusion. here is what I ment: test = ['10\t15', '16\t20', '25\t35', '45\t50', '55\t60', '61\t65', '75\t80'] I would get: 10 20 25 35 45 50 55 65 75 80 Here is my take on it: test =

[Tutor] List manipulation

2006-09-13 Thread Srinivas Iyyer
Dear group: I have a data like this: 10 15 16 20 25 35 45 50 55 60 61 65 75 80 Since 15 precedes 16, I want to consider 10:20 as one unit. If I repeat completely for data I would get: 10 20 25 35 45 50 55 65 75 80 test = ['10\t15',

Re: [Tutor] List manipulation

2006-09-13 Thread Bob Gailer
Srinivas Iyyer wrote: Dear group: I have a data like this: 10 15 16 20 25 35 45 50 55 60 61 65 75 80 Since 15 precedes 16, I want to consider 10:20 as one unit. If I repeat completely for data I would get: 10 20 25 35 45 50 55

Re: [Tutor] List manipulation

2006-09-13 Thread Srinivas Iyyer
Thank you Bob for your email. Sorry for the confusion. here is what I ment: test = ['10\t15', '16\t20', '25\t35', '45\t50', '55\t60', '61\t65', '75\t80'] x = [] y = [] for m in test: ... cols = m.split('\t') ... x.append(cols[0]) ... y.append(cols[1]) ... x ['10', '16', '25',

Re: [Tutor] List manipulation

2006-09-13 Thread Bob Gailer
try this: test = ['10\t15', '16\t20', '25\t35', '45\t50','55\t60', '61\t65', '75\t80'] t='\t'.join(test).split('\t') t ['10', '15', '16', '20', '25', '35', '45', '50', '55', '60', '61', '65', '75', '80'] t2=[int(i) for i in t] t2 [10, 15, 16, 20, 25, 35, 45, 50, 55, 60, 61, 65, 75,

[Tutor] List Box binding

2006-07-19 Thread Joe Cox
I am using Tk and have a series of Radio buttons that I want to bind to it's own listboxfor further selection. I just don't get the point how to click the button and select the proper listbox I want it tied too. Joe Cox513-293-4830 mobile[EMAIL PROTECTED]

Re: [Tutor] List Box binding

2006-07-19 Thread Kent Johnson
Joe Cox wrote: I am using Tk and have a series of Radio buttons that I want to bind to it's own listbox for further selection. I just don't get the point how to click the button and select the proper listbox I want it tied too. Do you mean you want clicking on the radio button to enable a

[Tutor] List methods/comps Best Practices

2006-04-03 Thread stv
I just thumped my head against the wall for a few hours on something, and I was wondering if it's just my green-ness in Python, or if I'm doing something unsavory. I had several list comprehensions that I was mucking with; these lists are working on a simple subclass of the built-in list object.

Re: [Tutor] List methods/comps Best Practices

2006-04-03 Thread Karl Pflästerer
On 3 Apr 2006, [EMAIL PROTECTED] wrote: I had several list comprehensions that I was mucking with; these lists are working on a simple subclass of the built-in list object. They looked liked this: filelist = getFilesToAdd() filelist2 = getFilesToDel() adds = MyList('foo') dels =

Re: [Tutor] List methods/comps Best Practices

2006-04-03 Thread Kent Johnson
stv wrote: # return all changes, deletes first return dels.extend(adds) Since extend returns None, I ran into a lot of not-iterable errors when calling this code. So I fixed this with dels.extend(adds) return dels And all is good, although it took way more head scratching than

Re: [Tutor] List methods/comps Best Practices

2006-04-03 Thread stv
So don't write: [adds.add_changes('foo', path) for path in filelist] but: for path in filelist: adds.add_changes('foo', path) Excellent point; new toy, got carrid away :) I feel silly on that one. And now that I've made the return list.extend(foo) mistake, I'll surely neve- ... er, wait

Re: [Tutor] list packing

2006-02-27 Thread Kent Johnson
kevin parks wrote: John, Thanks... i am liking this variation a tad more since it means i only have to type the path in one place but it is akin to your second one... i was (still am really) having a hard time understanding how to apply path.join _and_ listdir sometimes list

[Tutor] list packing

2006-02-26 Thread kevin parks
howdy, I am using the os module to do some of my heavy lifting for me. I am tried of building lists by hand so i decided that i would get python to look in a bunch of directories and stuff all the things it find there into a list depending on it's extension. Works great ... one problem

Re: [Tutor] list packing

2006-02-26 Thread John Fouhy
On 27/02/06, kevin parks [EMAIL PROTECTED] wrote: snd = [f for f in os.listdir('/Users/kevin/snd/') if f.endswith('.aif')] If this is all you need, then you could do something like: snd = ['/Users/kevin/snd/%s' % f for f in os.listdir('/Users/kevin/snd/') if f.endswith('.aif')] Or, slightly

Re: [Tutor] list packing

2006-02-26 Thread Sean Perry
John Fouhy wrote: On 27/02/06, kevin parks [EMAIL PROTECTED] wrote: snd = [f for f in os.listdir('/Users/kevin/snd/') if f.endswith('.aif')] If this is all you need, then you could do something like: snd = ['/Users/kevin/snd/%s' % f for f in os.listdir('/Users/kevin/snd/') if

Re: [Tutor] list method help

2006-02-03 Thread Rinzwind
On 2/3/06, Chris or Leslie Smith [EMAIL PROTECTED] wrote: Rinzwind wrote: | Well Chris or Leslie Smith. | | This bit l[:]=l[-1:]+l[0:-1] I think is VERY elegant. When I saw this | in your post I tought: DUH. | I did the same with 1 line more but I am still new to python ;) | You're seeing

Re: [Tutor] list method help

2006-02-03 Thread Kent Johnson
On 2/3/06, Chris or Leslie Smith [EMAIL PROTECTED] wrote: Others could give you a really good answer. I am a BASIC/FORTRAN writer myself, and getting used to the *object* orientation of python took a little while, but after you get the hang of it, it's not bad. In BASIC you think of variables

Re: [Tutor] list method help

2006-02-03 Thread Rinzwind
On 2/3/06, Kent Johnson [EMAIL PROTECTED] wrote: On 2/3/06, Chris or Leslie Smith [EMAIL PROTECTED] wrote:Others could give you a really good answer. I am a BASIC/FORTRAN writer myself, and getting used to the *object* orientation of python took a little while, but after you get the hang of it,

Re: [Tutor] list method help

2006-02-03 Thread Kent Johnson
Rinzwind wrote: On 2/3/06, *Kent Johnson* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: You definitely have to stop thinking of variables as containers. They are pointers or references to values. Another way to think of this is that variables are names for things. You may

Re: [Tutor] list method help

2006-02-03 Thread Danny Yoo
But this assignment sort of puzzles me to why it's done like this (maybe cuz I am not used to it and can not see beyond my own experience in coding (having a blind spot or something like that)). If we have a snippet of code like: ### def test(): x = [] f(x) print x

[Tutor] list method help

2006-02-02 Thread Michael Haft
Hello, was just trying to do something and tried the following code: list = [1, test, 1.5] for x in list: print list.pop(x) I get the following error: print list.pop(x) TypeError: an integer is required Does this mean i can't use a for loop to pop things from a list? or is

Re: [Tutor] list method help

2006-02-02 Thread Danny Yoo
On Thu, 2 Feb 2006, Michael Haft wrote: was just trying to do something and tried the following code: list = [1, test, 1.5] for x in list: print list.pop(x) I get the following error: print list.pop(x) TypeError: an integer is required Hi Michael, The error message

Re: [Tutor] list method help

2006-02-02 Thread Chris or Leslie Smith
| Hello, | was just trying to do something and tried the following code: | | list = [1, test, 1.5] | | for x in list: | print list.pop(x) | | I get the following error: | | print list.pop(x) | TypeError: an integer is required | | Does this mean i can't use a for loop to pop

[Tutor] list.__init__()

2006-01-26 Thread Christopher Spears
What purpose does list.__init__() play in the piece of code below? class Mylist(list): def __init__(self, value = []): list.__init__([]) self.concat(value) def concat(self, value): for x in value: if not x in

Re: [Tutor] list.__init__()

2006-01-26 Thread Kent Johnson
Christopher Spears wrote: What purpose does list.__init__() play in the piece of code below? It's an incorrect call to the base class __init__() function. This does base class initialization on the current list. The correct call is list.__init__(self) By the way this list seems to be doing

Re: [Tutor] List-question

2005-12-19 Thread Ed Singleton
On 19/12/05, Øyvind [EMAIL PROTECTED] wrote: I have one function that finds some values. Then I want that function to find new values based on the values it found first. However, by just looping, it starts on an eternal job. As illustrated in: list = [1,2,3] list2 = list list2 [1, 2,

[Tutor] List of class instances

2005-09-20 Thread Jan Eden
Hi, I'd like to form a list of class instances. The following does not work (TextfieldLong, Textarea, TextfieldShort etc being class names): fields = [ TextfieldLong(name='title', label='Seitentitel', value=''), Textarea(name='content', label='Inhalt', value=''),

Re: [Tutor] List of class instances

2005-09-20 Thread Jan Eden
Hi, Jan Eden wrote on 20.09.2005: Hi, I'd like to form a list of class instances. The following does not work (TextfieldLong, Textarea, TextfieldShort etc being class names): fields = [ TextfieldLong(name='title', label='Seitentitel', value=''), Textarea(name='content',

Re: [Tutor] List of class instances

2005-09-20 Thread Kent Johnson
Jan Eden wrote: I'd like to form a list of class instances. The following does not work (TextfieldLong, Textarea, TextfieldShort etc being class names): fields = [ TextfieldLong(name='title', label='Seitentitel', value=''), Textarea(name='content', label='Inhalt', value=''),

Re: [Tutor] List of class instances

2005-09-20 Thread Jan Eden
Hi, Orri Ganel wrote on 20.09.2005: As a side-note, unless you're okay with only being able to access those instance variables through the fields list (ie fields[0], fields[1], fields[2]), you may want to actually name them first. Yes, I am fine with that - I actually prefer to have a sorted

[Tutor] New entry in the Tutor list - Question: Python and dbf files

2005-07-08 Thread Alessandro Brollo
I'm using Python 2.3 in Win32/WinXP context. I'm new at all to newsgroups and discussion lists; the first help I need, is how to learn good-manner use of such very effective, but time-consuming tools. My approach will be a try-and-error one; I encourage all of you to send me any

Re: [Tutor] List of regular expressions

2005-06-22 Thread Ewald Ertl
Hi Shidan! on Wed, 22 Jun 2005 00:28:44 -0400 Shidan [EMAIL PROTECTED] wrote : - Shidan Hi I have a list of regular expression patterns like such: Shidan Shidan thelist =

Re: [Tutor] List of regular expressions

2005-06-22 Thread Alan G
for pattern in thelist: regex=re.compile(pattern) if regex.match('24110'): the_pattern = pattern . . sys.exit(0) but in this case it will pick thelist[2] and not the list[3] as I wanted to, how can I have it pick the pattern that describes it better from

Re: [Tutor] List of regular expressions

2005-06-22 Thread Danny Yoo
On Wed, 22 Jun 2005, Shidan wrote: Hi I have a list of regular expression patterns like such: thelist = ['^594694.*','^689.*','^241.*', '^241(0[3-9]|1[0145]|2[0-9]|3[0-9]|41|5[1-37]|6[138]|75|8[014579]).*'] Now I want to iterate thru each of these like: for pattern in thelist:

[Tutor] List of regular expressions

2005-06-21 Thread Shidan
Hi I have a list of regular expression patterns like such: thelist = ['^594694.*','^689.*','^241.*','^241(0[3-9]|1[0145]|2[0-9]|3[0-9]|41|5[1-37]|6[138]|75|8[014579]).*'] Now I want to iterate thru each of these like: for pattern in thelist: regex=re.compile(pattern) if

[Tutor] List processing

2005-06-01 Thread cgw501
Hi, I have a load of files I need to process. Each line of a file looks something like this: eYAL001C1 Spar81 3419451845192 1 So basically its a table, separated with tabs. What I need to do is make a new file where all the entries in the table are

Re: [Tutor] List processing

2005-06-01 Thread Danny Yoo
On 1 Jun 2005 [EMAIL PROTECTED] wrote: I have a load of files I need to process. [text cut] So basically its a table, separated with tabs. What I need to do is make a new file where all the entries in the table are those where the values in columns 1 and 5 were present as a pair more than

Re: [Tutor] List processing

2005-06-01 Thread Terry Carroll
On 1 Jun 2005 [EMAIL PROTECTED] wrote: eYAL001C1 Spar81 3419451845192 1 So basically its a table, separated with tabs. What I need to do is make a new file where all the entries in the table are those where the values in columns 1 and 5 were present as

Re: [Tutor] List processing

2005-06-01 Thread Kent Johnson
[EMAIL PROTECTED] wrote: Hi, I have a load of files I need to process. Each line of a file looks something like this: eYAL001C1 Spar81 3419451845192 1 So basically its a table, separated with tabs. What I need to do is make a new file where all

Re: [Tutor] List processing

2005-06-01 Thread Alan G
I have a load of files I need to process. Each line of a file looks something like this: eYAL001C1 Spar 81 3419 4518 4519 2 1 So basically its a table, separated with tabs. What I need to do is make a new file where all the entries in the table are those where the values in columns 1 and 5

[Tutor] List comprehensions

2005-03-23 Thread Liam Clarke
Hi, Is there a way to apply multiple actions within one list comprehension? i.e. instead of a = [] for i in x: i.pop(3) g = [ int(item) for item in i] a.append(g) Is there any guides to this (possibly obtuse) tool? Regards, Liam Clarke PS I can see how nested list

RE: [Tutor] List comprehensions

2005-03-23 Thread Ryan Davis
Clarke Sent: Wednesday, March 23, 2005 5:44 AM To: Tutor Tutor Subject: [Tutor] List comprehensions Hi, Is there a way to apply multiple actions within one list comprehension? i.e. instead of a = [] for i in x: i.pop(3) g = [ int(item) for item in i] a.append(g) Is there any guides

Re: [Tutor] List comprehensions

2005-03-23 Thread Sean Perry
Liam Clarke wrote: Is there any guides to this (possibly obtuse) tool? Think of it this way. A list comprehension generates a new list. So, you should think about list comps whenever you have old_list - new_list style behavior. There are two advantages to list comps over map: 1) a list comp can

Re: [Tutor] List comprehensions

2005-03-23 Thread Kent Johnson
Liam Clarke wrote: Is there any guides to this (possibly obtuse) tool? http://docs.python.org/tut/node7.html#SECTION00714 http://www.amk.ca/python/2.0/index.html#SECTION00060 Kent ___ Tutor maillist - Tutor@python.org

Re: [Tutor] List comprehensions

2005-03-23 Thread John Fouhy
Ryan Davis wrote: I think map is a little cleaner is some cases. Not sure if its more Pythonic, I'm still trying to figure out exactly what that means. map is (probably) going to be removed in Python3000 :-( So it's probably better to not get into the habit of using it. -- John.

[Tutor] Seek advise to code Re: Fw: Please submit to tutor list: dictionary update prob

2005-01-24 Thread Eri Mendz
Kent Johnson kent37 at tds.net writes: [snip] You still aren't doing anything with newdic. The absence of 'newdic' in the code after 'read.close()' should be a clue I think you want to overwrite the saved dict, but with the new dict instead of with a filename string... Hi Kent,

[Tutor] OT: list as newsgroup (was: Please submit to tutor list: dictionary update prob)

2005-01-20 Thread Wolfram Kraus
Jacob S. wrote: Hi everyone, sent this on to the list as told to. cc to eri to verify my sending to list... ;-) Jacob dear jacob, sorry to send this to you but if you may, kindly send to tutor list as im no longer subscribed. my problem is in the update dict portion: it just doesnt update

[Tutor] Re: Fw: Please submit to tutor list: dictionary update prob

2005-01-20 Thread Eri Mendz
Kent Johnson kent37 at tds.net writes: Jacob S. wrote: sorry to send this to you but if you may, kindly send to tutor list as im no longer subscribed. my problem is in the update dict portion: it just doesnt update regardless how many contacts i add. kindly advise where my mistake

[Tutor] Fw: Please submit to tutor list: dictionary update prob

2005-01-19 Thread Jacob S.
Hi everyone, sent this on to the list as told to. cc to eri to verify my sending to list... ;-) Jacob dear jacob, sorry to send this to you but if you may, kindly send to tutor list as im no longer subscribed. my problem is in the update dict portion: it just doesnt update regardless how many

Re: [Tutor] Fw: Please submit to tutor list: dictionary update prob

2005-01-19 Thread Kent Johnson
Jacob S. wrote: sorry to send this to you but if you may, kindly send to tutor list as im no longer subscribed. my problem is in the update dict portion: it just doesnt update regardless how many contacts i add. kindly advise where my mistake is or code gone wrong. the rest of the options i

Re: [Tutor] List comprehensions

2005-01-13 Thread Max Noel
On Jan 13, 2005, at 04:13, Bob Gailer wrote: I like Kent's response. foobar(item)/0 is a valid expression. It fits the grammar of expressions. The fact that it raises an exception does not make it an invalid expression. Consider foobar(item)/xyz. It is valid. If xyz == 0 then it will also

Re: [Tutor] List comprehensions

2005-01-13 Thread Kent Johnson
Blake Winton wrote: Kent Johnson wrote: If you mean for j to be a list of foobar(item) then use j=[foobar(item) for item in x] The first part of the list comp can be any valid expression. Does that mean that there are invalid expressions? I'd enjoy seeing an example. I suppose if it's an

Re: [Tutor] List comprehensions

2005-01-12 Thread jfouhy
Quoting Liam Clarke [EMAIL PROTECTED]: As a comprehension, if you get what I mean... Can I build a for loop with a function in for x in x part? Ack. Having difficulty summing it up properly. I'm not sure exactly what you mean, so my answer is probably. from math import sin arr =

Re: [Tutor] List comprehensions

2005-01-12 Thread Kent Johnson
If you mean for j to be a list of foobar(item) then use j=[foobar(item) for item in x] The first part of the list comp can be any valid expression. Kent Liam Clarke wrote: Hi, Am I able to achieve something like this - def foobar(); # stuff return x=[1,1000] for j=foobar(item) for item in

Re: [Tutor] List comprehensions

2005-01-12 Thread Liam Clarke
Aah, thank you both - I knew there was a way to do it. Regards, Liam Clarke PS John - another Kiwi, seems to be a lot of NZers involved in Python Python projects. Is it the No. 8 wire freedom of Python? ; ) On Wed, 12 Jan 2005 18:48:39 -0500, Kent Johnson [EMAIL PROTECTED] wrote: If you

Re: [Tutor] List comprehensions

2005-01-12 Thread Bob Gailer
At 04:48 PM 1/12/2005, Kent Johnson wrote: If you mean for j to be a list of foobar(item) then use j=[foobar(item) for item in x] The first part of the list comp can be any valid expression. Does that mean that there are invalid expressions? I'd enjoy seeing an example. Bob Gailer mailto:[EMAIL

Re: [Tutor] List comprehensions

2005-01-12 Thread Kent Johnson
I suppose if it's an expression, it must be valid, eh? Otherwise it's something else. Bob Gailer wrote: At 04:48 PM 1/12/2005, Kent Johnson wrote: If you mean for j to be a list of foobar(item) then use j=[foobar(item) for item in x] The first part of the list comp can be any valid expression.

<    2   3   4   5   6   7