Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import glob
  2.  
  3. filenames = glob.glob('*.dat')
  4.  
  5. for file in filenames:
  6.     data = open(file)
  7.     if file.startswith('weather'):
  8.         weather_data_list = []
  9.  
  10.         for line in data:
  11.             weather_data_list += [line.split()]
  12.  
  13.         separate_days_data = [x for x in weather_data_list[2:]]
  14.         temperatures_list = [x[:3] for x in separate_days_data[:-1]]
  15.         numeric_lists = [[elem.replace('*', '') for elem in lst] for lst in
  16.                          temperatures_list]  # Remove asterisks from string
  17.         values = [[int(x) for x in sublist] for sublist in numeric_lists]
  18.         max_temperatures = [x[1] for x in values]
  19.         min_temperatures = [x[2] for x in values]
  20.         subtraction_results = [x - y for x, y in zip(max_temperatures, min_temperatures)]
  21.         day_with_smallest_temp_spread = subtraction_results.index(min(subtraction_results)) + 1
  22.  
  23.         print('Day with smallest temperature spread is day number', day_with_smallest_temp_spread)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement