Re: [Tutor] Having an Issue
On Fri, Mar 13, 2009 at 8:43 PM, Jared White wrote: > I dunno how this works but hopefully someone can help me > > I am trying to build a program in Python but for someone i can not get what > i am trying to build WORK > > by email you guys is there a way i can get some help some pointer on the > program i am trying to solve Yes, just send your questions to the list and we will try to help. It works best if you can - clearly describe what you are trying to do - show what you have tried so far - tell us what happens, including full error messages if any Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Having an Issue
I dunno how this works but hopefully someone can help me I am trying to build a program in Python but for someone i can not get what i am trying to build WORK by email you guys is there a way i can get some help some pointer on the program i am trying to solve Thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help
A hollow voice says PLUGH. Be sure your lantern is lit! -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help
Sanhita Mallick wrote: help YOU ARE STANDING AT THE END OF A ROAD BEFORE A SMALL BRICK BUILDING . AROUND YOU IS A FOREST. A SMALL STREAM FLOWS OUT OF THE BUILDING AND DOWN A GULLY. Emile ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] help
help --- On Sat, 3/14/09, tutor-requ...@python.org wrote: > From: tutor-requ...@python.org > Subject: Tutor Digest, Vol 61, Issue 50 > To: tutor@python.org > Date: Saturday, March 14, 2009, 5:18 AM > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body > 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more > specific > than "Re: Contents of Tutor digest..." > > > Today's Topics: > >1. update list of dictionaries based on key (ski) >2. Re: update list of dictionaries based on key (greg > whittier) >3. Re: update list of dictionaries based on key (ski) >4. best gui for the job? (W W) >5. Re: best gui for the job? (Lie Ryan) > > > -- > > Message: 1 > Date: Fri, 13 Mar 2009 16:09:58 +0100 > From: ski > Subject: [Tutor] update list of dictionaries based on key > To: python tutor > Message-ID: <49ba7746.6090...@khine.net> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Hello, > Here is what I have so far: > > >>> mylist = [{'index': 0, > 'title': 'Association of British Travel > Agents', 'selected': False, 'edit_row': > '?edit_affiliation=0', > 'affiliation': 'ABTA', > 'affiliation_no': u'G3903'}, > {'index': 1, > 'title': 'Appointed Agents of IATA', > 'selected': False, 'edit_row': > '?edit_affiliation=1', 'affiliation': > 'IATA', 'affiliation_no': > u'none'}, {'index': 0, 'title': > 'Association of Airline Cons.', > 'selected': False, 'edit_row': > '?edit_affiliation=0', 'affiliation': > 'AAC', 'affiliation_no': u'sss'}, > {'index': 1, 'title': 'Association of > British Travel Agents', 'selected': False, > 'edit_row': > '?edit_affiliation=1', 'affiliation': > 'ABTA', 'affiliation_no': u'zser'}] > > >>> key = 'affiliation_no' > > >>> my_dup_keys = [] > >>> merged_list = [] > > >>> mykeys = [item['affiliation'] for > item in mylist] > > >>> for x in mykeys: > if mykeys.count(x) >= 2: > my_dup_keys.append(x) > > >>> for item in mylist: > if item['affiliation'] in set(my_dup_keys): > merged_list.append(item) > > > >>> values = [d[key] for d in merged_list if > d.has_key(key)] > >>> for dict in merged_list: > dict[key] = values > mylist.append(dict) > > >>> print mylist > [{'index': 0, 'title': 'Association of > British Travel Agents', > 'selected': False, 'edit_row': > '?edit_affiliation=0', 'affiliation': > 'ABTA', 'affiliation_no': > [u'G3903', u'zser']}, {'index': 1, > 'title': > 'Appointed Agents of IATA', 'selected': > False, 'edit_row': > '?edit_affiliation=1', 'affiliation': > 'IATA', 'affiliation_no': > u'none'}, {'index': 0, 'title': > 'Association of Airline Cons.', > 'selected': False, 'edit_row': > '?edit_affiliation=0', 'affiliation': > 'AAC', 'affiliation_no': u'sss'}, > {'index': 1, 'title': 'Association of > British Travel Agents', 'selected': False, > 'edit_row': > '?edit_affiliation=1', 'affiliation': > 'ABTA', 'affiliation_no': > [u'G3903', u'zser']}, {'index': 0, > 'title': 'Association of British > Travel Agents', 'selected': False, > 'edit_row': '?edit_affiliation=0', > 'affiliation': 'ABTA', > 'affiliation_no': [u'G3903', > u'zser']}, {'index': > 1, 'title': 'Association of British Travel > Agents', 'selected': False, > 'edit_row': '?edit_affiliation=1', > 'affiliation': 'ABTA', > 'affiliation_no': [u'G3903', > u'zser']}] > > > This sort of works but I want to return a list that updates > 'mylist' not > append to it, so I will get: > > [{'index': 0, 'title': 'Association of > British Travel Agents', > 'selected': False, 'edit_row': > '?edit_affiliation=0', 'affiliation': > 'ABTA', 'affiliation_no': > [u'G3903', u'zser']}, {'index': 1, > 'title': > 'Appointed Agents of IATA', 'selected': > False, 'edit_row': > '?edit_affiliation=1', 'affiliation': > 'IATA', 'affiliation_no': > u'none'}, {'index': 0, 'title': > 'Association of Airline Cons.', > 'selected': False, 'edit_row': > '?edit_affiliation=0', 'affiliation': > 'AAC', 'affiliation_no': u'sss'}] > > > Thanks > > Norman > > > > -- > > Message: 2 > Date: Fri, 13 Mar 2009 11:43:19 -0400 > From: greg whittier > Subject: Re: [Tutor] update list of dictionaries based on > key > To: python tutor > Message-ID: > > Content-Type: text/plain; charset=ISO-8859-1 > > On Fri, Mar 13, 2009 at 11:09 AM, ski > wrote: > > Hello, > > Here is what I have so far: > > > mylist = [{'index': 0, > 'title': 'Association of British Travel > Agents', > 'selected': False, > 'edit_row': '?edit_affiliation=0', > 'affiliation': 'ABTA', > 'affiliation_no': > u'G3903'}, {'i
Re: [Tutor] best gui for the job?
On Fri, Mar 13, 2009 at 1:18 PM, Lie Ryan wrote: > W W wrote: > > What do you mean "good enough resolution"? I suppose I really meant quality - the shapes I drew with PIL were severely aliased, but maybe I didn't do it right. -Wayne -- To be considered stupid and to be told so is more painful than being called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, every vice, has found its defenders, its rhetoric, its ennoblement and exaltation, but stupidity hasn’t. - Primo Levi ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] best gui for the job?
W W wrote: Hi, What is the best gui to implement a simple paint-esque program in? I already built a really simple one in Tkinter - but Tkinter lacks a save functionality. I considered using the PIL to draw in the background, but it didn't seem to have a good enough resolution. I thought about pyGTK because I have some familiarity with that, but I can't find any examples of saving a drawingarea. What do you mean "good enough resolution"? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] best gui for the job?
Hi, What is the best gui to implement a simple paint-esque program in? I already built a really simple one in Tkinter - but Tkinter lacks a save functionality. I considered using the PIL to draw in the background, but it didn't seem to have a good enough resolution. I thought about pyGTK because I have some familiarity with that, but I can't find any examples of saving a drawingarea. Also, to clarify what I mean by "best" - I want it to be fairly simple to implement (my non-saving sketch in a single color/size is about 100 lines), yet extensible - I'd like the ability to further enhance my program down the road. Changing the opacity, and the possibility to work with layers is a plus. If anyone has tips or knows of any tutorials (I haven't really been able to find anything suitable), please let me know. Thanks for any suggestions, Wayne -- To be considered stupid and to be told so is more painful than being called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, every vice, has found its defenders, its rhetoric, its ennoblement and exaltation, but stupidity hasn’t. - Primo Levi ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] update list of dictionaries based on key
greg whittier wrote: On Fri, Mar 13, 2009 at 11:09 AM, ski wrote: Hello, Here is what I have so far: mylist = [{'index': 0, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'ABTA', 'affiliation_no': u'G3903'}, {'index': 1, 'title': 'Appointed Agents of IATA', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'IATA', 'affiliation_no': u'none'}, {'index': 0, 'title': 'Association of Airline Cons.', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'AAC', 'affiliation_no': u'sss'}, {'index': 1, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'ABTA', 'affiliation_no': u'zser'}] key = 'affiliation_no' my_dup_keys = [] merged_list = [] mykeys = [item['affiliation'] for item in mylist] for x in mykeys: if mykeys.count(x) >= 2: my_dup_keys.append(x) for item in mylist: if item['affiliation'] in set(my_dup_keys): merged_list.append(item) values = [d[key] for d in merged_list if d.has_key(key)] for dict in merged_list: dict[key] = values mylist.append(dict) print mylist [{'index': 0, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'ABTA', 'affiliation_no': [u'G3903', u'zser']}, {'index': 1, 'title': 'Appointed Agents of IATA', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'IATA', 'affiliation_no': u'none'}, {'index': 0, 'title': 'Association of Airline Cons.', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'AAC', 'affiliation_no': u'sss'}, {'index': 1, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'ABTA', 'affiliation_no': [u'G3903', u'zser']}, {'index': 0, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'ABTA', 'affiliation_no': [u'G3903', u'zser']}, {'index': 1, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'ABTA', 'affiliation_no': [u'G3903', u'zser']}] This sort of works but I want to return a list that updates 'mylist' not append to it, so I will get: [{'index': 0, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'ABTA', 'affiliation_no': [u'G3903', u'zser']}, {'index': 1, 'title': 'Appointed Agents of IATA', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'IATA', 'affiliation_no': u'none'}, {'index': 0, 'title': 'Association of Airline Cons.', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'AAC', 'affiliation_no': u'sss'}] It's a little hard to figure what you're getting at. This looks like a table represented by a list of dictionaries that you'd like to group by "affiliation." i have objects in my database, called addresses, each address has a metadata called affiliation. also each address is a member of a company. in my company class, i wanted to get all the addresses affiliations and only list the unique values. affiliation_nos = {} for row in mylist: affiliation_nos.set_default(row['affiliation'],[]).append(row['affliation_no']) will give you a list of affiliation_no's for each affiliation and if you want a list of dicts, you could do mynewlist = [dict(affiliation=affiliation, affiliation_nos = affiliation_nos[affiliation]) for affiliation in affiliation_nos.keys()] I don't know what to do about all the other fields though. In your example input list you have two dictionaries with affiliation = 'ABTA'. In your output you kept the one with index=0 and threw away index=1. (same for 'edit_row') How do you determine which to keep? I want to keep it based on the 'affiliation' key. In essence, from my original 'mylist' I want to keep all the list items as they are, but just update the list items that have more than one 'affiliation' by updating only the 'affiliation_no' to contain both entries. Perhaps there is a simpler way to do this ;) I will change my code so that mylist does not contain the 'index' and 'edit_row' keys. Perhaps then it will be easier to update the dictionary? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] update list of dictionaries based on key
On Fri, Mar 13, 2009 at 11:09 AM, ski wrote: > Hello, > Here is what I have so far: > mylist = [{'index': 0, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'ABTA', 'affiliation_no': u'G3903'}, {'index': 1, 'title': 'Appointed Agents of IATA', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'IATA', 'affiliation_no': u'none'}, {'index': 0, 'title': 'Association of Airline Cons.', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'AAC', 'affiliation_no': u'sss'}, {'index': 1, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'ABTA', 'affiliation_no': u'zser'}] > key = 'affiliation_no' > my_dup_keys = [] merged_list = [] > mykeys = [item['affiliation'] for item in mylist] > for x in mykeys: > if mykeys.count(x) >= 2: > my_dup_keys.append(x) > for item in mylist: > if item['affiliation'] in set(my_dup_keys): > merged_list.append(item) > > values = [d[key] for d in merged_list if d.has_key(key)] for dict in merged_list: > dict[key] = values > mylist.append(dict) > print mylist > [{'index': 0, 'title': 'Association of British Travel Agents', 'selected': > False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'ABTA', > 'affiliation_no': [u'G3903', u'zser']}, {'index': 1, 'title': 'Appointed > Agents of IATA', 'selected': False, 'edit_row': '?edit_affiliation=1', > 'affiliation': 'IATA', 'affiliation_no': u'none'}, {'index': 0, 'title': > 'Association of Airline Cons.', 'selected': False, 'edit_row': > '?edit_affiliation=0', 'affiliation': 'AAC', 'affiliation_no': u'sss'}, > {'index': 1, 'title': 'Association of British Travel Agents', 'selected': > False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'ABTA', > 'affiliation_no': [u'G3903', u'zser']}, {'index': 0, 'title': 'Association > of British Travel Agents', 'selected': False, 'edit_row': > '?edit_affiliation=0', 'affiliation': 'ABTA', 'affiliation_no': [u'G3903', > u'zser']}, {'index': 1, 'title': 'Association of British Travel Agents', > 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'ABTA', > 'affiliation_no': [u'G3903', u'zser']}] > > > This sort of works but I want to return a list that updates 'mylist' not > append to it, so I will get: > > [{'index': 0, 'title': 'Association of British Travel Agents', 'selected': > False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'ABTA', > 'affiliation_no': [u'G3903', u'zser']}, {'index': 1, 'title': 'Appointed > Agents of IATA', 'selected': False, 'edit_row': '?edit_affiliation=1', > 'affiliation': 'IATA', 'affiliation_no': u'none'}, {'index': 0, 'title': > 'Association of Airline Cons.', 'selected': False, 'edit_row': > '?edit_affiliation=0', 'affiliation': 'AAC', 'affiliation_no': u'sss'}] > It's a little hard to figure what you're getting at. This looks like a table represented by a list of dictionaries that you'd like to group by "affiliation." affiliation_nos = {} for row in mylist: affiliation_nos.set_default(row['affiliation'],[]).append(row['affliation_no']) will give you a list of affiliation_no's for each affiliation and if you want a list of dicts, you could do mynewlist = [dict(affiliation=affiliation, affiliation_nos = affiliation_nos[affiliation]) for affiliation in affiliation_nos.keys()] I don't know what to do about all the other fields though. In your example input list you have two dictionaries with affiliation = 'ABTA'. In your output you kept the one with index=0 and threw away index=1. (same for 'edit_row') How do you determine which to keep? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] update list of dictionaries based on key
Hello, Here is what I have so far: >>> mylist = [{'index': 0, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'ABTA', 'affiliation_no': u'G3903'}, {'index': 1, 'title': 'Appointed Agents of IATA', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'IATA', 'affiliation_no': u'none'}, {'index': 0, 'title': 'Association of Airline Cons.', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'AAC', 'affiliation_no': u'sss'}, {'index': 1, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'ABTA', 'affiliation_no': u'zser'}] >>> key = 'affiliation_no' >>> my_dup_keys = [] >>> merged_list = [] >>> mykeys = [item['affiliation'] for item in mylist] >>> for x in mykeys: if mykeys.count(x) >= 2: my_dup_keys.append(x) >>> for item in mylist: if item['affiliation'] in set(my_dup_keys): merged_list.append(item) >>> values = [d[key] for d in merged_list if d.has_key(key)] >>> for dict in merged_list: dict[key] = values mylist.append(dict) >>> print mylist [{'index': 0, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'ABTA', 'affiliation_no': [u'G3903', u'zser']}, {'index': 1, 'title': 'Appointed Agents of IATA', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'IATA', 'affiliation_no': u'none'}, {'index': 0, 'title': 'Association of Airline Cons.', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'AAC', 'affiliation_no': u'sss'}, {'index': 1, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'ABTA', 'affiliation_no': [u'G3903', u'zser']}, {'index': 0, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'ABTA', 'affiliation_no': [u'G3903', u'zser']}, {'index': 1, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'ABTA', 'affiliation_no': [u'G3903', u'zser']}] This sort of works but I want to return a list that updates 'mylist' not append to it, so I will get: [{'index': 0, 'title': 'Association of British Travel Agents', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'ABTA', 'affiliation_no': [u'G3903', u'zser']}, {'index': 1, 'title': 'Appointed Agents of IATA', 'selected': False, 'edit_row': '?edit_affiliation=1', 'affiliation': 'IATA', 'affiliation_no': u'none'}, {'index': 0, 'title': 'Association of Airline Cons.', 'selected': False, 'edit_row': '?edit_affiliation=0', 'affiliation': 'AAC', 'affiliation_no': u'sss'}] Thanks Norman ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor