Skip to content

Instantly share code, notes, and snippets.

@leahein
Last active October 23, 2016 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leahein/e3b0d6f660c9e520cd19ea584265265a to your computer and use it in GitHub Desktop.
Save leahein/e3b0d6f660c9e520cd19ea584265265a to your computer and use it in GitHub Desktop.
Sort
def sort_by(self, criteria):
keywords = list()
for keyword, data in self.report.items():
keywords.append((keyword, data[criteria]))
return sorted(keywords, key=operator.itemgetter(1))
Adwords(report).sort_by("Clicks")
# =>[('Do Androids Dream of Electric Sheep? ', 109), ('science fiction books about time travel', 50),
# ('science fiction books about space', 10), ('doctor who books', 8), ('I, Robot', 3)...]
Adwords(report).sort_by("Impressions")
# => [('science fiction books about the future', 1000), ("The Hitchhiker's Guide to the Galaxy", 346),
# ('science fiction books about robots', 152), ("The Hitchhiker's Guide to the Galaxy"', 100), ('I, Robot', 55), ...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment