python3: Fix usage of .keys()/.values() to handle iterators.

This fixes the places where we use the result of .keys(), .items(),
and .values() that wouldn't work with an iterator to wrap them with
list().
This commit is contained in:
Tim Abbott 2016-01-24 16:27:18 -08:00
parent a8c4facc67
commit b9eacb19c9
2 changed files with 7 additions and 9 deletions

View file

@ -64,16 +64,14 @@ def generate_support_stats():
analyze_messages(msgs, word_count, email_count)
if True:
words = word_count.keys()
words = [w for w in words if word_count[w] >= 10]
words = [w for w in words if len(w) >= 5]
words = [w for w in word_count.keys() if word_count[w] >= 10 and len(w) >= 5]
words = sorted(words, key=lambda w: word_count[w], reverse=True)
for word in words:
print(word, word_count[word])
if False:
emails = email_count.keys()
emails = sorted(emails, key=lambda w: email_count[w], reverse=True)
emails = sorted(list(email_count.keys()),
key=lambda w: email_count[w], reverse=True)
for email in emails:
print(email, email_count[email])

View file

@ -2347,7 +2347,7 @@ class P4Sync(Command, P4UserMap):
self.labels[newestChange] = [output, revisions]
if self.verbose:
print("Label changes: %s" % self.labels.keys())
print("Label changes: %s" % (list(self.labels.keys()),))
# Import p4 labels as git tags. A direct mapping does not
# exist, so assume that if all the files are at the same revision
@ -2780,7 +2780,7 @@ class P4Sync(Command, P4UserMap):
if short in branches:
self.p4BranchesInGit = [ short ]
else:
self.p4BranchesInGit = branches.keys()
self.p4BranchesInGit = list(branches.keys())
if len(self.p4BranchesInGit) > 1:
if not self.silent:
@ -3215,7 +3215,7 @@ commands = {
def main():
if len(sys.argv[1:]) == 0:
printUsage(commands.keys())
printUsage(list(commands.keys()))
sys.exit(2)
cmdName = sys.argv[1]
@ -3225,7 +3225,7 @@ def main():
except KeyError:
print("unknown command %s" % cmdName)
print("")
printUsage(commands.keys())
printUsage(list(commands.keys()))
sys.exit(2)
options = cmd.options