From: Serge N. <Ser...@fr...> - 2009-01-04 18:01:11
|
Hi, Le/The vendredi 02 janvier 2009, Don Allingham a écrit/wrote : > And if you want to have a bit of fun with Python, and see its power, you > can do something like this: > > person_list = [ self.database.get_person_from_handle(ref_handle) > for (ref_handle, ref_type) in self.database.find_backlink_handles(evt_handle) > if ref_type == 'Person' ] Fantastic ! This is what I was looking for. however, you made a mistake. The second line is : for (ref_type, ref_handle) in self.database.find_backlink_handles(evt_handle) ref_type and ref_handle are inverted. > The above returns the list of Person objects associated with the > particular event handle. It performs the same function as Gary's > original code, but in a more compact and faster form. > > Python list comprehensions are very powerful, and once you get used to > them, they are very easy to understand. As you iterate through a list, > you can filter and transform the data all in the same statement. > > Don ... Serge |