Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pipelined generator
#1
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
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

.csv   techcrunch.csv (Size: 91.34 KB / Downloads: 67)
Reply


Messages In This Thread
pipelined generator - by akbarza - Oct-26-2023, 11:10 AM
RE: pipelined generator - by Gribouillis - Oct-26-2023, 12:19 PM
RE: pipelined generator - by akbarza - Oct-30-2023, 10:10 AM
RE: pipelined generator - by deanhystad - Oct-28-2023, 04:13 AM
RE: pipelined generator - by akbarza - Oct-28-2023, 08:12 AM
RE: pipelined generator - by Gribouillis - Oct-28-2023, 11:30 AM
RE: pipelined generator - by akbarza - Oct-30-2023, 10:05 AM
RE: pipelined generator - by DeaD_EyE - Oct-29-2023, 02:41 PM
RE: pipelined generator - by deanhystad - Oct-30-2023, 11:46 AM
RE: pipelined generator - by akbarza - Oct-31-2023, 10:59 AM
RE: pipelined generator - by Gribouillis - Oct-31-2023, 12:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  receive from a generator, send to a generator Skaperen 9 5,651 Feb-05-2018, 06:26 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020