From 1e8ce58f5d0db22714d65ff440045a7526ed394d Mon Sep 17 00:00:00 2001 From: Skip Montanaro Date: Mon, 6 Aug 2007 21:07:53 +0000 Subject: [PATCH] remove most uses of list(somedict.keys()) in Demo scripts --- Demo/cgi/cgi2.py | 2 +- Demo/classes/Dbm.py | 4 ++-- Demo/metaclasses/Enum.py | 4 ++-- Demo/newmetaclasses/Enum.py | 2 +- Demo/pdist/cmdfw.py | 4 +--- Demo/pdist/cmptree.py | 2 +- Demo/pdist/cvslib.py | 17 ++++++----------- Demo/pdist/rrcs.py | 8 +++----- Demo/pdist/server.py | 4 +--- Demo/scripts/ftpstats.py | 7 ++----- Demo/scripts/markov.py | 2 +- Demo/scripts/newslist.py | 3 +-- Demo/threads/Coroutine.py | 2 +- Demo/tix/samples/OptMenu.py | 2 +- Demo/tkinter/guido/AttrDialog.py | 6 +++--- Demo/xml/elem_count.py | 6 +++--- Demo/xml/roundtrip.py | 2 +- 17 files changed, 31 insertions(+), 46 deletions(-) diff --git a/Demo/cgi/cgi2.py b/Demo/cgi/cgi2.py index 239fb6b5f95..1d5822c463f 100755 --- a/Demo/cgi/cgi2.py +++ b/Demo/cgi/cgi2.py @@ -14,7 +14,7 @@ def main(): print("

No Form Keys

") else: print("

Form Keys

") - for key in list(form.keys()): + for key in form.keys(): value = form[key].value print("

", cgi.escape(key), ":", cgi.escape(value)) diff --git a/Demo/classes/Dbm.py b/Demo/classes/Dbm.py index fd735718760..ecc117d4953 100755 --- a/Demo/classes/Dbm.py +++ b/Demo/classes/Dbm.py @@ -12,7 +12,7 @@ class Dbm: def __repr__(self): s = '' - for key in list(self.keys()): + for key in self.keys(): t = repr(key) + ': ' + repr(self[key]) if s: t = ', ' + t s = s + t @@ -32,7 +32,7 @@ class Dbm: def keys(self): res = [] - for key in list(self.db.keys()): + for key in self.db.keys(): res.append(eval(key)) return res diff --git a/Demo/metaclasses/Enum.py b/Demo/metaclasses/Enum.py index 8d402db9775..eb52d79cee2 100644 --- a/Demo/metaclasses/Enum.py +++ b/Demo/metaclasses/Enum.py @@ -42,7 +42,7 @@ class EnumMetaClass: self.__name__ = name self.__bases__ = bases self.__dict = {} - for key, value in list(dict.items()): + for key, value in dict.items(): self.__dict[key] = EnumInstance(name, key, value) def __getattr__(self, name): @@ -80,7 +80,7 @@ class EnumMetaClass: s = s + '(' + string.join([x.__name__ for x in self.__bases__], ", ") + ')' if self.__dict: list = [] - for key, value in list(self.__dict.items()): + for key, value in self.__dict.items(): list.append("%s: %s" % (key, int(value))) s = "%s: {%s}" % (s, string.join(list, ", ")) return s diff --git a/Demo/newmetaclasses/Enum.py b/Demo/newmetaclasses/Enum.py index 0f7f913fb09..99b6fe80415 100644 --- a/Demo/newmetaclasses/Enum.py +++ b/Demo/newmetaclasses/Enum.py @@ -20,7 +20,7 @@ class EnumMetaclass(type): def __init__(cls, name, bases, dict): super(EnumMetaclass, cls).__init__(name, bases, dict) cls._members = [] - for attr in list(dict.keys()): + for attr in dict.keys(): if not (attr.startswith('__') and attr.endswith('__')): enumval = EnumInstance(name, attr, dict[attr]) setattr(cls, attr, enumval) diff --git a/Demo/pdist/cmdfw.py b/Demo/pdist/cmdfw.py index 7bcb4616b78..ec854b1bc74 100755 --- a/Demo/pdist/cmdfw.py +++ b/Demo/pdist/cmdfw.py @@ -104,9 +104,7 @@ class CommandFrameWork: c = c.__bases__[0] if docstrings: print("where subcommand can be:") - names = list(docstrings.keys()) - names.sort() - for name in names: + for name in sorted(docstrings.keys()): print(docstrings[name]) if self.PostUsageMessage: print(self.PostUsageMessage) diff --git a/Demo/pdist/cmptree.py b/Demo/pdist/cmptree.py index d6962e95ad3..1e9f985e721 100755 --- a/Demo/pdist/cmptree.py +++ b/Demo/pdist/cmptree.py @@ -89,7 +89,7 @@ def compare(local, remote, mode): else: print("same mtime but different sum?!?!", end=' ') print() - for name in list(lsumdict.keys()): + for name in lsumdict.keys(): if not list(rsumdict.keys()): print(repr(name), "only locally", end=' ') fl() diff --git a/Demo/pdist/cvslib.py b/Demo/pdist/cvslib.py index 8ccb6166bd6..78e4fbb4c9d 100755 --- a/Demo/pdist/cvslib.py +++ b/Demo/pdist/cvslib.py @@ -223,15 +223,12 @@ class CVS: f.close() def getlocalfiles(self): - list = list(self.entries.keys()) + entries_keys = set(self.entries.keys()) addlist = os.listdir(os.curdir) for name in addlist: - if name in list: - continue if not self.ignored(name): - list.append(name) - list.sort() - for file in list: + entries_keys.add(name) + for file in sorted(entries_keys): try: e = self.entries[file] except KeyError: @@ -257,19 +254,17 @@ class CVS: print('-'*50) def keys(self): - keys = list(self.entries.keys()) - keys.sort() - return keys + return sorted(self.entries.keys()) def values(self): def value(key, self=self): return self.entries[key] - return list(map(value, list(self.keys()))) + return [value(k) for k in self.keys()] def items(self): def item(key, self=self): return (key, self.entries[key]) - return list(map(item, list(self.keys()))) + return [item(k) for k in self.keys()] def cvsexists(self, file): file = os.path.join("CVS", file) diff --git a/Demo/pdist/rrcs.py b/Demo/pdist/rrcs.py index 8d0ef0358da..647ecc5c054 100755 --- a/Demo/pdist/rrcs.py +++ b/Demo/pdist/rrcs.py @@ -71,11 +71,9 @@ def unlock(x, copts, fn): x.unlock(fn) def info(x, copts, fn): - dict = x.info(fn) - keys = list(dict.keys()) - keys.sort() - for key in keys: - print(key + ':', dict[key]) + info_dict = x.info(fn) + for key in sorted(info_dict.keys()): + print(key + ':', info_dict[key]) print('='*70) def head(x, copts, fn): diff --git a/Demo/pdist/server.py b/Demo/pdist/server.py index 98a47411d8f..7e779712a9e 100755 --- a/Demo/pdist/server.py +++ b/Demo/pdist/server.py @@ -101,9 +101,7 @@ class Server: def _listmethods(self, cl=None): if not cl: cl = self.__class__ - names = list(cl.__dict__.keys()) - names = [x for x in names if x[0] != '_'] - names.sort() + names = sorted([x for x in cl.__dict__.keys() if x[0] != '_']) for base in cl.__bases__: basenames = self._listmethods(base) basenames = list(filter(lambda x, names=names: x not in names, basenames)) diff --git a/Demo/scripts/ftpstats.py b/Demo/scripts/ftpstats.py index d0a08249dcd..19ad3928ccd 100755 --- a/Demo/scripts/ftpstats.py +++ b/Demo/scripts/ftpstats.py @@ -106,9 +106,7 @@ def showbar(dict, title): n = len(title) print('='*((70-n)/2), title, '='*((71-n)/2)) list = [] - keys = list(dict.keys()) - keys.sort() - for key in keys: + for key in sorted(dict.keys()): n = len(str(key)) list.append((len(dict[key]), key)) maxkeylength = 0 @@ -128,8 +126,7 @@ def show(dict, title, maxitems): n = len(title) print('='*((70-n)/2), title, '='*((71-n)/2)) list = [] - keys = list(dict.keys()) - for key in keys: + for key in dict.keys(): list.append((-len(dict[key]), key)) list.sort() for count, key in list[:maxitems]: diff --git a/Demo/scripts/markov.py b/Demo/scripts/markov.py index a91e3594ef0..3dc57ce63af 100755 --- a/Demo/scripts/markov.py +++ b/Demo/scripts/markov.py @@ -87,7 +87,7 @@ def test(): return if debug: print('done.') if debug > 1: - for key in list(m.trans.keys()): + for key in m.trans.keys(): if key is None or len(key) < histsize: print(repr(key), m.trans[key]) if histsize == 0: print(repr(''), m.trans['']) diff --git a/Demo/scripts/newslist.py b/Demo/scripts/newslist.py index 4635f1d8d6e..7038380f5c0 100755 --- a/Demo/scripts/newslist.py +++ b/Demo/scripts/newslist.py @@ -172,10 +172,9 @@ def printtree(f, tree, indent, p): createpage(p[1:], tree, p) return - kl = list(tree.keys()) + kl = sorted(tree.keys()) if l > 1: - kl.sort() if indent > 0: # Create a sub-list f.write('

  • '+p[1:]+'\n