Feb-13-2020, 09:16 AM
(Feb-13-2020, 02:37 AM)palladium Wrote: Hopefully there's no redundant stuff hereGiven that you want to learn about generators, I will keep your approach although there are better ways to do this.
1. you can combine line 2 and 3 into one generator expression.
2. it's better to use
with
context manager to open the file3. line 5 can be list directly, instead of making it generator expression and immediately make it list on the next line
4. same for lines 7-11
you may want to look at cav.DictReader module
and you can iterate over the file handler directly, instead of creating a generator
import csv with open("techcruncher.csv") as f: rdr = csv.DictReader(f) round_a_funding = [int(item["raisedAmt"]) for item in rdr if item["round"] == 'a'] print(f'Average Round A funding is {sum(round_a_funding)/len(round_a_funding):.2f}')as an alternative you may look at Pandas to process the data as dataframe.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs