[Tutor] Unnecessary comprehension warning
boB Stepp
robertvstepp at gmail.com
Sat Jun 6 22:19:47 EDT 2020
Continuing "Exercise 3.12: Using your library module" in "3.4 Modules" at
https://dabeaz-course.github.io/practical-python/Notes/03_Program_organization/04_Modules.html.
I rewrote another function in report.py, read_prices(), to make use of the
parse_csv() function in the fileparse module. The rewritten function is:
def read_prices(filename: str) -> Dict[str, float]:
"""Read a file of stock prices and load them into a dictionary."""
prices = fileparse.parse_csv(filename, types=[str, float], has_headers=False)
stock_prices = {stock_name: stock_price for stock_name, stock_price in prices}
return stock_prices
pylint complains with:
report.py|25 col 1 warning| unnecessary-comprehension: Unnecessary use of a comprehension
The dictionary comprehension I'm now using replaces a lengthier for loop
with indexing instead of nice names. Am I truly doing things in a bad
Python style as the linter is complaining? Should I be doing this
differently?
--
Wishing you only the best,
boB Stepp
More information about the Tutor
mailing list