[geneagrapher] 157/226: Replaced two of the information extraction loops with list comprehensions.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Sat Jul 11 17:10:58 UTC 2015
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to branch master
in repository geneagrapher.
commit 8375cde160871df4a0bebdd09c19c1a43e30832e
Author: David Alber <alber.david at gmail.com>
Date: Mon Oct 31 21:23:00 2011 -0700
Replaced two of the information extraction loops with list comprehensions.
---
geneagrapher/grabber.py | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/geneagrapher/grabber.py b/geneagrapher/grabber.py
index 8eb715f..1412f56 100644
--- a/geneagrapher/grabber.py
+++ b/geneagrapher/grabber.py
@@ -25,7 +25,7 @@ class Grabber:
@staticmethod
def extract_id(tag):
"""Extract the ID from a tag with form <a href="id.php?id=7401">."""
- return tag.attrs[0][-1].split('=')[-1]
+ return int(tag.attrs[0][-1].split('=')[-1])
def extract_node_information(self):
"""
@@ -59,14 +59,13 @@ class Grabber:
self.year = int(inst_year)
# Get advisor IDs.
- for advisor_info in soup.findAll(text=re.compile('Advisor')):
- if 'Advisor: Unknown' not in advisor_info:
- advisor_id = self.extract_id(advisor_info.findNext())
- self.advisors.append(int(advisor_id))
+ self.advisors = [self.extract_id(info.findNext()) for info in
+ soup.findAll(text=re.compile('Advisor'))
+ if 'Advisor: Unknown' not in info]
# Get descendant IDs.
if soup.find('table') is not None:
- for descendant_info in soup.find('table').findAll('a'):
- descendant_id = self.extract_id(descendant_info)
- self.descendants.append(int(descendant_id))
+ self.descendants = [self.extract_id(info) for info in
+ soup.find('table').findAll('a')]
+
return [self.name, self.institution, self.year, self.advisors, self.descendants]
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/geneagrapher.git
More information about the debian-science-commits
mailing list