Question: Please help with python program 1. Set up an empty list, capitals: 2. Read the data from EuropeanCapitals.csv file, one line at a time.
Please help with python program """ 1. Set up an empty list, capitals: 2. Read the data from EuropeanCapitals.csv file, one line at a time. 3. Skip the first line or the header line. 4. For each of the rest of the lines: strip the ending split line into 3 fields: city, pop, country convert pop into an int then make the 3 fields into a list and append the list to the capitals list 5. CLOSE THE FILE - from now on you're using the LIST, not the FILE ----------------------------------------------------------------- 6. Find (using the LIST, not the FILE) and print out: a - number of countries (n) b - total population for these "big" cities of Europe c - average population for the n "big" cities d - city with the largest population and show city, population & country 7. Sort the capitals list on city Print out sorted data - 1 country per line (city, pop, country) 8. Sort the capitals list on country Print out sorted data - 1 country per line (city, pop, country) [Hint: To sort on a field other than the 0th field in the inner list, do: 1) import the itemgetter function from the operator class: from operator import itemgetter 2) add a parameter to the sort function or the sorted function to specify which field you want to be the SORT KEY - i.e.,: new_list = sorted(the_list, key=itemgetter(2)) or the_list.sort(key=itemgetter(2)) for country as the SORT KEY """
city, population, country Amsterdam,863000,Netherlands Andorra la Vella,23000,Andorra Athens,664000,Greece Belgrade,1100000,Serbia Berlin,3400000,Germany Bern,130000,Switzerland Bratislava,450000,Slovakia Brussels,140000,Belgium Bucharest,2100000,Romania Budapest,1970000,Hungary Chisinau,670000,Moldova Copenhagen,1360000,Denmark Dublin,540000,Ireland Helsinki,500000,Finland Kiev,2650000,Ukraine Lisbon,670000,Portugal Ljubljana,280000,Slovenia London,7000000,United Kingdom Luxembourg,78000,Luxembourg Madrid,3000000,Spain Minsk,1700000,Belarus Monaco,28000,Monaco Moscow,8500000,Russia Nicosia,180000,Cyprus Nuuk,15000,Greenland Oslo,480000,Norway Paris,2200000,France Podgorica,1100000,Montenegro Prague,1250000,Czech Republic Reykjavik,100000,Iceland Riga,850000,Latvia Rome,2700000,Italy San Marino,2800,San Marino Sarajevo,500000,Bosnia & Herzegovina Skopje,450000,Macedonia; Rep. of Sofia,1150000,Bulgaria Stockholm,720000,Sweden Tallinn,450000,Estonia Tirana,250000,Albania Vaduz,5000,Liechtenstein Valletta,9300,Malta Vatican City,800,Holy See Vienna,1600000,Austria Vilnius,600000,Lithuania Warsaw,1660000,Poland Zagreb,850000,Croatia
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
