Re: [Tutor] update list of dictionaries based on key

2009-03-13 Thread ski
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', &#x

[Tutor] update list of dictionaries based on key

2009-03-13 Thread ski
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_ro

Re: [Tutor] merging dictionary values based on key

2009-03-12 Thread ski
how would you do this for a specific key instead of all the keys? greg whittier wrote: On Thu, Mar 12, 2009 at 4:24 PM, ski wrote: Hello, I have this issue, which I am unsure on how to solve. mylist1 = {'a': 'x123', 'b':'12'} mylist2 = {'a':

[Tutor] merging dictionary values based on key

2009-03-12 Thread ski
Hello, I have this issue, which I am unsure on how to solve. >>> mylist1 = {'a': 'x123', 'b':'12'} >>> mylist2 = {'a': 'x234', 'c': 'a23'} >>> for k in mylist2: ... if k in mylist1: ... mylist1[k] = [mylist1[k], mylist2[k]] ... else: ... mylist1[k] = mylist2[k] ...

Re: [Tutor] comparing lists of dictionaries

2009-03-09 Thread ski
i was looking to list all the items in list1 that are not in list2 based on the key['id] and key['affiliation'] respectively. thanks Kent Johnson wrote: On Mon, Mar 9, 2009 at 4:20 PM, ski wrote: what am i missing here, i would like to get a list of the diff between

[Tutor] comparing lists of dictionaries

2009-03-09 Thread ski
hello again, i am trying to get my head around this but without success, here is what i have so far: >>> list1 = [{'is_selected': False, 'id': 'AAC', 'title': 'Association of Airline Cons.'}, {'is_selected': False, 'id': 'AALA', 'title': 'Adv. Activity Licence. Auth.'}, {'is_selected': False,

[Tutor] compare csv file values against a python dictionary and create a new list from this.

2009-03-09 Thread ski
hello, i have created this function that compares the values of a csv file against a dictionary, you can see the code, here http://paste.lisp.org/display/76705 the affiliations list has 130 items. is there a better way to build the 'items' list? thanks norman ___

Re: [Tutor] creating new dictionary based on membership testing

2009-03-09 Thread ski
thank you all, great feedback. Sander Sweers wrote: 2009/3/9 A.T.Hofkamp : You can do something like [d for d in d1 if d['is_selected'] == False] to get your dicts. If 'is_selected' is not always present, it gets a bit more complicated, I'll leave that as an exercise for the interested reader

[Tutor] creating new dictionary based on membership testing

2009-03-09 Thread ski
hello, i have this list which contains a number of dictionaries. >>>d1 = [{'is_selected': False, 'id': 'AAC', 'title': 'Association of Airline Cons.'}, {'is_selected': False, 'id': 'AALA', 'title': 'Adv. Activity Licence. Auth.'}, {'is_selected': False, 'id': 'ABPCO', 'title': 'Association of

[Tutor] using re groups

2009-03-06 Thread ski
Hello, I have this: >>> import re >>> s = "Association of British Travel Agents (ABTA) No. 56542\nAir Travel Organisation Licence (ATOL)\nAppointed Agents of IATA (IATA)\nIncentive Travel & Meet. Association (ITMA)" >>> licenses = re.split("\n+", s) >>> licenseRe = re.compile(r'\(([A-Z]+)\)( N