''' Purpose: determine a rough estimate of the geocenter of the continental USA ''' # get access to web-based data support import url # specify dataset web location CSV_WEB_FOLDER = 'http://www.cs.virginia.edu/~cs1112/datasets/csv/' USA_DATASET = CSV_WEB_FOLDER + 'continental-usa.csv' # get the dataset of interest dataset = url.get_dataset( USA_DATASET ) # print(dataset) # determine webfile header and location data header = dataset[ 0 ] # THE FIRST ROW IN OUR DATASET # ['Zip Code', 'City','State','Latitude','Longitude'] locations = dataset[ 1 : ] # all of the other rows (the data with specific # information with cities and everything) # determine geocenter # a loop that might be helpful for solving the problem latitudes = [] longitudes = [] for entry in locations : # print('Entry=', entry) # entry is each row in our locations list [[],[]..] zipcode, town, state, latitude, longitude = entry # Assign 5 variables to # small parts of entry latitudes.append( latitude ) longitudes.append( longitude ) # Your lists can consist of anything: ints, floats, strings, more lists # etc. # So you're gonna get a list of floats (decimals) of latitudes and longitudes n = len( latitudes ) # The number of latitudes and longitudes and entries I have sum_latitudes = sum( latitudes ) # sum function sums up every value in list sum_longitudes = sum( longitudes ) # sum function sums up every value in list average_latitude = sum_latitudes / n average_longitude = sum_longitudes / n guess1_lat , guess1_long = average_latitude, average_longitude min_latitude = min( latitudes ) min_longitude = min( longitudes ) max_latitude = max( latitudes ) max_longitude = max( longitudes ) guess2_lat = ( max_latitude + min_latitude ) / 2 guess2_long = ( max_longitude + min_longitude ) / 2 middle_index = n//2 sorted_latitudes = sorted( latitudes ) sorted_longitudes = sorted( longitudes ) guess3_lat = sorted_latitudes[middle_index] guess3_long = sorted_longitudes[middle_index] print(guess1_lat, guess1_long) print(guess2_lat, guess2_long) print(guess3_lat, guess3_long) s = ['abc','xyz','123','ABC'] t = sorted( s ) print( t ) # if you do a,b = ['banana', 'apple'] then a is assigned banana # and b is assigned apple # s = 'banana apple' # a, b = s.split() -> a, b = ['banana', 'apple']