Oct-26-2023, 11:10 AM
hi
in the below code, pipelined generator has been used to sum values in a" techcrunch.csv" file and the code is in site:
https://realpython.com/introduction-to-p...generators
I thought about it, but I did not find anything.
do you have any suggestions?
second question:
(in IDLE), when I want to see the methods of a generator, I first create a generator and then I write dir(name of the generator).
it is time-consuming.
is it possible to without creating a generator, see methods related to generators? ( for string, without creating a string, I write dir(str))
also, I have this question about the result of the command"file=open(address)". namely, i want dir(f) without creating f.
I always do this time-consuming:
f= open(an address of a file)
dir(f)
thanks
in the below code, pipelined generator has been used to sum values in a" techcrunch.csv" file and the code is in site:
https://realpython.com/introduction-to-p...generators
file_name = "techcrunch.csv"
lines = (line for line in open(file_name))
list_line = (s.rstrip().split(",") for s in lines)
cols = next(list_line)
company_dicts = (dict(zip(cols, data)) for data in list_line)
funding = (
int(company_dict["raisedAmt"])
for company_dict in company_dicts
if company_dict["round"] == "a"
)
total_series_a = sum(funding)
print(f"Total series A fundraising: ${total_series_a}")it is some ambiguous, however, at the end of the page has suggested changing this code so that in addition to sum, the average of the values should be calculated.I thought about it, but I did not find anything.
do you have any suggestions?
second question:
(in IDLE), when I want to see the methods of a generator, I first create a generator and then I write dir(name of the generator).
it is time-consuming.
is it possible to without creating a generator, see methods related to generators? ( for string, without creating a string, I write dir(str))
also, I have this question about the result of the command"file=open(address)". namely, i want dir(f) without creating f.
I always do this time-consuming:
f= open(an address of a file)
dir(f)
thanks
Attached Files
