Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with Generator
#3
Thanks for the tip.

I tried the following and it works. Hopefully there's no redundant stuff here:

file_name = "techcruncher.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)
z = list(company_dicts)
funding = (
        int(item["raisedAmt"])
        for item in z
        if item["round"] == 'a')
x = list(funding)
print(sum(x)/len(x))
Reply


Messages In This Thread
Problem with Generator - by palladium - Feb-11-2020, 03:46 AM
RE: Problem with Generator - by buran - Feb-11-2020, 04:48 AM
RE: Problem with Generator - by palladium - Feb-13-2020, 02:37 AM
RE: Problem with Generator - by buran - Feb-13-2020, 09:16 AM
RE: Problem with Generator - by DeaD_EyE - Feb-13-2020, 01:26 PM
RE: Problem with Generator - by palladium - Feb-16-2020, 02:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in using generator akbarza 2 692 Nov-07-2023, 08:40 AM
Last Post: perfringo
  list call problem in generator function using iteration and recursive calls postta 1 2,013 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  receive from a generator, send to a generator Skaperen 9 5,695 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