Revision: 6703 Author: nicdumz Date: 2009-04-25 09:15:50 +0000 (Sat, 25 Apr 2009)
Log Message: ----------- CompareLanguages: use set operations to do set intersection/substraction.
Modified Paths: -------------- trunk/pywikipedia/interwiki.py
Modified: trunk/pywikipedia/interwiki.py =================================================================== --- trunk/pywikipedia/interwiki.py 2009-04-25 08:45:33 UTC (rev 6702) +++ trunk/pywikipedia/interwiki.py 2009-04-25 09:15:50 UTC (rev 6703) @@ -1663,24 +1663,17 @@ return len(self.subjects)
def compareLanguages(old, new, insite): - removing = [] - adding = [] - modifying = [] - for site in old.keys(): - if site not in new: - removing.append(old[site]) - elif old[site] != new[site]: - modifying.append(new[site])
- for site2 in new.keys(): - if site2 not in old: - adding.append(new[site2]) - mods = "" + oldiw = set(old) + newiw = set(new) + # sort by language code - adding.sort() - modifying.sort() - removing.sort() + adding = sorted(newiw - oldiw) + removing = sorted(oldiw - newiw) + modifying = sorted(site for site in oldiw & newiw if old[site] != new[site])
+ mods = "" + if len(adding) + len(removing) + len(modifying) <= 3: # Use an extended format for the string linking to all added pages. fmt = lambda page: page.aslink(forceInterwiki=True)
pywikipedia-svn@lists.wikimedia.org