-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery Starbot ⭐ refactored ccombe/practical-python #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,10 +22,6 @@ def portfolio_cost(filename): | |
| return total_cost | ||
|
|
||
| import sys | ||
| if len(sys.argv) == 2: | ||
| filename = sys.argv[1] | ||
| else: | ||
| filename = input('Enter a filename:') | ||
|
|
||
| filename = sys.argv[1] if len(sys.argv) == 2 else input('Enter a filename:') | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| cost = portfolio_cost(filename) | ||
| print('Total cost:', cost) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| # bounce.py | ||
|
|
||
| height = 100 | ||
| bounce = 1 | ||
| while bounce <= 10: | ||
| height = height * (3/5) | ||
| for bounce in range(1, 11): | ||
| height *= 3/5 | ||
| print(bounce, round(height, 4)) | ||
| bounce += 1 | ||
|
Comment on lines
-4
to
-8
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,10 +23,6 @@ def portfolio_cost(filename): | |
| return total_cost | ||
|
|
||
| import sys | ||
| if len(sys.argv) == 2: | ||
| filename = sys.argv[1] | ||
| else: | ||
| filename = input('Enter a filename:') | ||
|
|
||
| filename = sys.argv[1] if len(sys.argv) == 2 else input('Enter a filename:') | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| cost = portfolio_cost(filename) | ||
| print('Total cost:', cost) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,10 +39,7 @@ def parse_csv(filename, select=None, types=None, has_headers=True, delimiter=',' | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,10 +39,7 @@ def parse_csv(filename, select=None, types=None, has_headers=True, delimiter=',' | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,13 +7,9 @@ def portfolio_cost(filename): | |
| Computes the total cost (shares*price) of a portfolio file | ||
| ''' | ||
| portfolio = report.read_portfolio(filename) | ||
| return sum([s['shares']*s['price'] for s in portfolio]) | ||
| return sum(s['shares']*s['price'] for s in portfolio) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| import sys | ||
| if len(sys.argv) == 2: | ||
| filename = sys.argv[1] | ||
| else: | ||
| filename = input('Enter a filename:') | ||
|
|
||
| filename = sys.argv[1] if len(sys.argv) == 2 else input('Enter a filename:') | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| cost = portfolio_cost(filename) | ||
| print('Total cost:', cost) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,10 +39,7 @@ def parse_csv(filename, select=None, types=None, has_headers=True, delimiter=',' | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ def portfolio_cost(filename): | |
| Computes the total cost (shares*price) of a portfolio file | ||
| ''' | ||
| portfolio = report.read_portfolio(filename) | ||
| return sum([s['shares'] * s['price'] for s in portfolio]) | ||
| return sum(s['shares'] * s['price'] for s in portfolio) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def main(args): | ||
| if len(args) != 2: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,10 +38,7 @@ def parse_csv(lines, select=None, types=None, has_headers=True, delimiter=',', s | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ def portfolio_cost(filename): | |
| Computes the total cost (shares*price) of a portfolio file | ||
| ''' | ||
| portfolio = report.read_portfolio(filename) | ||
| return sum([s['shares'] * s['price'] for s in portfolio]) | ||
| return sum(s['shares'] * s['price'] for s in portfolio) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def main(args): | ||
| if len(args) != 2: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,10 +30,7 @@ def parse_csv(filename, select=None, types=None, has_headers=True, delimiter=',' | |
| row = [func(val) for func, val in zip(types, row)] | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,10 +38,7 @@ def parse_csv(lines, select=None, types=None, has_headers=True, delimiter=',', s | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ def portfolio_cost(filename): | |
| Computes the total cost (shares*price) of a portfolio file | ||
| ''' | ||
| portfolio = report.read_portfolio(filename) | ||
| return sum([s.cost() for s in portfolio]) | ||
| return sum(s.cost() for s in portfolio) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def main(args): | ||
| if len(args) != 2: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,8 +14,7 @@ def read_portfolio(filename): | |
| select=['name','shares','price'], | ||
| types=[str,int,float]) | ||
|
|
||
| portfolio = [ Stock(d['name'], d['shares'], d['price']) for d in portdicts ] | ||
| return portfolio | ||
| return [ Stock(d['name'], d['shares'], d['price']) for d in portdicts ] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def read_prices(filename): | ||
| ''' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,10 +38,7 @@ def parse_csv(lines, select=None, types=None, has_headers=True, delimiter=',', s | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ def portfolio_cost(filename): | |
| Computes the total cost (shares*price) of a portfolio file | ||
| ''' | ||
| portfolio = report.read_portfolio(filename) | ||
| return sum([s.cost() for s in portfolio]) | ||
| return sum(s.cost() for s in portfolio) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def main(args): | ||
| if len(args) != 2: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,7 @@ def read_portfolio(filename): | |
| select=['name','shares','price'], | ||
| types=[str,int,float]) | ||
|
|
||
| portfolio = [ Stock(d['name'], d['shares'], d['price']) for d in portdicts ] | ||
| return portfolio | ||
| return [ Stock(d['name'], d['shares'], d['price']) for d in portdicts ] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def read_prices(filename): | ||
| ''' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,10 +38,7 @@ def parse_csv(lines, select=None, types=None, has_headers=True, delimiter=',', s | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ def portfolio_cost(filename): | |
| Computes the total cost (shares*price) of a portfolio file | ||
| ''' | ||
| portfolio = report.read_portfolio(filename) | ||
| return sum([s.cost() for s in portfolio]) | ||
| return sum(s.cost() for s in portfolio) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def main(args): | ||
| if len(args) != 2: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,8 +14,7 @@ def read_portfolio(filename): | |
| select=['name','shares','price'], | ||
| types=[str,int,float]) | ||
|
|
||
| portfolio = [ Stock(d['name'], d['shares'], d['price']) for d in portdicts ] | ||
| return portfolio | ||
| return [ Stock(d['name'], d['shares'], d['price']) for d in portdicts ] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def read_prices(filename): | ||
| ''' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,10 +38,7 @@ def parse_csv(lines, select=None, types=None, has_headers=True, delimiter=',', s | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,11 +14,11 @@ def __getitem__(self, index): | |
| return self._holdings[index] | ||
|
|
||
| def __contains__(self, name): | ||
| return any([s.name == name for s in self._holdings]) | ||
| return any(s.name == name for s in self._holdings) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| @property | ||
| def total_cost(self): | ||
| return sum([s.shares * s.price for s in self._holdings]) | ||
| return sum(s.shares * s.price for s in self._holdings) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def tabulate_shares(self): | ||
| from collections import Counter | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,10 +38,7 @@ def parse_csv(lines, select=None, types=None, has_headers=True, delimiter=',', s | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,10 +38,7 @@ def parse_csv(lines, select=None, types=None, has_headers=True, delimiter=',', s | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,11 +14,11 @@ def __getitem__(self, index): | |
| return self._holdings[index] | ||
|
|
||
| def __contains__(self, name): | ||
| return any([s.name == name for s in self._holdings]) | ||
| return any(s.name == name for s in self._holdings) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| @property | ||
| def total_cost(self): | ||
| return sum([s.shares * s.price for s in self._holdings]) | ||
| return sum(s.shares * s.price for s in self._holdings) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def tabulate_shares(self): | ||
| from collections import Counter | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,10 +38,7 @@ def parse_csv(lines, select=None, types=None, has_headers=True, delimiter=',', s | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,11 +14,11 @@ def __getitem__(self, index): | |
| return self._holdings[index] | ||
|
|
||
| def __contains__(self, name): | ||
| return any([s.name == name for s in self._holdings]) | ||
| return any(s.name == name for s in self._holdings) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| @property | ||
| def total_cost(self): | ||
| return sum([s.shares * s.price for s in self._holdings]) | ||
| return sum(s.shares * s.price for s in self._holdings) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def tabulate_shares(self): | ||
| from collections import Counter | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,10 +38,7 @@ def parse_csv(lines, select=None, types=None, has_headers=True, delimiter=',', s | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,10 +38,7 @@ def parse_csv(lines, select=None, types=None, has_headers=True, delimiter=',', s | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,10 +38,7 @@ def parse_csv(lines, select=None, types=None, has_headers=True, delimiter=',', s | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,10 +38,7 @@ def parse_csv(lines, select=None, types=None, has_headers=True, delimiter=',', s | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,10 +40,7 @@ def parse_csv(lines, select=None, types=None, has_headers=True, delimiter=',', s | |
| continue | ||
|
|
||
| # Make a dictionary or a tuple | ||
| if headers: | ||
| record = dict(zip(headers, row)) | ||
| else: | ||
| record = tuple(row) | ||
| record = dict(zip(headers, row)) if headers else tuple(row) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| records.append(record) | ||
|
|
||
| return records | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines
14-23refactored with the following changes:aug-assign)