[Tutor] Iterate through dictionary values and remove item

2008-05-14 Thread GTXY20
Hello all, I have dictionary like the following: d={(1,23A):[a,b,c,d], (1,24A):[b,c,d], (2,23A):[a,b], (2,24A):[a,b,c,d]} I would like to iterate through the dictionary such that if it finds the value 'a' in the values of the key that it would remove the value 'b' from the values list. In addit

[Tutor] looking for ways to get diff between two txt files

2008-05-14 Thread Kamal
Hi, I would really appreciate if someone help to find a way to calculate delta (diff) between two similar text files. I have looked at difflib and found related script at this site http://www.java2s.com/Code/Python/Utility/Printfilediffsincontextunifiedorndiffformats.htm Is there a simple way to

Re: [Tutor] basic lists and loops question

2008-05-14 Thread Jon Crump
Kent, On Wed, 14 May 2008, Kent Johnson wrote: I understand about removing elements from a container you're iterating. Is data.remove(x) problematic in this context? Yes. It can cause the iteration to skip elements ofthe list. Better to post-process the list with a list comprehension: evts = [

Re: [Tutor] basic lists and loops question

2008-05-14 Thread Kent Johnson
On Wed, May 14, 2008 at 9:06 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: >> I understand about removing elements from a container you're iterating. Is >> data.remove(x) problematic in this context? > > Yes. It can cause the iteration to skip elements of the list. For example: In [1]: l=range(5) I

Re: [Tutor] basic lists and loops question

2008-05-14 Thread Kent Johnson
On Wed, May 14, 2008 at 6:03 PM, Jon Crump <[EMAIL PROTECTED]> wrote: > def events(data): > evts = [] > for x in data: >for y in data: > if (x['placename'] == y['placename']) and (x['end'].month + 1 == > y['start'].month) and (y['start'] - x['end'] == datetime.timedelta(1)): >x['

Re: [Tutor] basic lists and loops question

2008-05-14 Thread Jon Crump
Bob, and Kent, Many thanks! Sounds like the key 'processed' is created by the assignment x['processed'] = True. So those dictionaries that have not experienced this assignment have no such key. You should instead use: if 'processed' in x: Doh! Now that WAS obvious Try lst.remove(x) Now t

Re: [Tutor] basic lists and loops question

2008-05-14 Thread Kent Johnson
On Wed, May 14, 2008 at 3:02 PM, Jon Crump <[EMAIL PROTECTED]> wrote: > Something basic about lists and loops that I'm not getting here. > I have a function that searches through them to find pairs of dictionaries > that satisfy certain criteria. When the nested loops find such a pair, I > need to

Re: [Tutor] basic lists and loops question

2008-05-14 Thread bob gailer
Jon Crump wrote: Something basic about lists and loops that I'm not getting here. I've got a long list of dictionaries that looks like this: lst = [{'placename': u'Stow, Lincolnshire', 'long-name': u'Stow, Lincolnshire.', 'end': datetime.date(1216, 9, 28), 'start': datetime.date(1216, 9, 26)}

[Tutor] basic lists and loops question

2008-05-14 Thread Jon Crump
Something basic about lists and loops that I'm not getting here. I've got a long list of dictionaries that looks like this: lst = [{'placename': u'Stow, Lincolnshire', 'long-name': u'Stow, Lincolnshire.', 'end': datetime.date(1216, 9, 28), 'start': datetime.date(1216, 9, 26)}, {'placename': u'

Re: [Tutor] Else Clause In A Loop

2008-05-14 Thread Simón A. Ruiz
kinuthia muchane wrote: On Tue, 2008-05-13 at 11:09 -0400, "Simón A. Ruiz" wrote: When i is 3, then we'll only check (2 % 3 == 0) which is False, so the loop ends unbroken and runs the else clause letting us know that 3 is indeed a prime number. Shouldn't we be checking for (3%2 == 0) instead

Re: [Tutor] destroying a window once a movie has stoped playing

2008-05-14 Thread bhaaluu
On Tue, May 13, 2008 at 9:07 PM, <[EMAIL PROTECTED]> wrote: > > > def movieu(self): > mov_name = "video.mpg" > pygame.mixer.quit() > screen = pygame.display.set_mode((320, 240)) > video = pygame.movie.Movie(mov_name) > screen = pygame.display.set_mode(v

Re: [Tutor] Help with class.self variables

2008-05-14 Thread Kent Johnson
On Wed, May 14, 2008 at 3:45 AM, Mark <[EMAIL PROTECTED]> wrote: > i want to set the keys of the user row as the keys of User self > but i m not sure how to do it > > for i in self._user.keys(): > self[i]=self._user[i] Should be setattr(self, i, self._user[i]) > You ca

[Tutor] James D Mcclatchey is out of the office.

2008-05-14 Thread James D Mcclatchey
I will be out of the office starting 05/14/2008 and will not return until 05/19/2008. I will respond to your message when I return. ***IMPORTANT NOTICE: This communication, including any attachment, contains information that may be confidential or privileged, and is intended solely for the e

[Tutor] Help with class.self variables

2008-05-14 Thread Mark
im trying to create a class user so that i can do r=User(1) r._user.keys() ['rating', 'last_name', 'pageviews', 'ip', 'number_polls', 'site', 'myrand', 'hotmail', 'number_activities', 'skype', 'id', 'city', 'rawpassword', 'number_useraudios', 'zip', 'number_votes', 'last_login', 'number_u