Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions code/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ def __init__(self):

soup = BeautifulSoup(html_source, 'html.parser')
links = soup.findAll("a")
data = []
for count, elem in enumerate(links):
data.append(elem)

data = [elem for count, elem in enumerate(links)]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Example.__init__ refactored with the following changes:

  • Convert for loop into list comprehension

print(browser.title)
print(str(len(data)) + 'Links found')

Expand Down
5 changes: 1 addition & 4 deletions code/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@

soup = BeautifulSoup(html_source, 'html.parser')
links = soup.findAll("a")
data = []
for count, elem in enumerate(links):
data.append(elem)

data = [elem for count, elem in enumerate(links)]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 27-30 refactored with the following changes:

  • Convert for loop into list comprehension

print(browser.title)
print(str(len(data)) + 'Links found')

Expand Down