Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import csv
- def download_files():
- #This function creates two .dat files necessary for further calculations
- weather_source = requests.get('http://codekata.com/data/04/weather.dat')
- football_source = requests.get('http://codekata.com/data/04/football.dat')
- with open('weather.dat', 'wb') as f:
- f.write(weather_source.content)
- with open('football.dat', 'wb') as f:
- f.write(football_source.content)
- def smallest_temperature_difference():
- weather = open('weather.dat')
- weather_data_list =[]
- for line in weather:
- weather_data_list += [line.split()]
- separate_days_data = [x for x in weather_data_list[2:]]
- temperatures_list = [x[:3] for x in separate_days_data[:-1]]
- numeric_lists = [[elem.replace('*', '') for elem in lst] for lst in temperatures_list] #Remove asterisks from string
- values = [[int(x) for x in sublist] for sublist in numeric_lists]
- max_temperatures = [x[1] for x in values]
- min_temperatures = [x[2] for x in values]
- subtraction_results = [x - y for x, y in zip(max_temperatures, min_temperatures)]
- day_with_smallest_temp_spread = subtraction_results.index(min(subtraction_results))+1
- print('Day with smallest temperature spread is day number', day_with_smallest_temp_spread)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement