Question: Description:(PYTHON) John was sitting near to a fireplace in his house, trying to get some warmth from the fire. Fighting his cold at the end

 Description:(PYTHON) John was sitting near to a fireplace in his house,

Description:(PYTHON) John was sitting near to a fireplace in his house, trying to get some warmth from the fire. Fighting his cold at the end of a freezing, short, dark winter day, he started wondering why it always had to be so cold during this season. That was when he came up with an idea. John stated that winter is the initial part of the year in which it is always colder than in the remaining part. This latter part is called 'summer'. Then he assumed that summer is always warmer than winter; that is, any temperature measured in winter is colder than every temperature measured in summer. Then he searched the Internet and found the previous year' s meteorological data, which contained the year's temperature measurements. He began to wonder if it might be possible to divide the year into winter and summer so that winter comes before summer and each winter' s temperature measurement is smaller than any temperature measured in summer. In case there are many such possible partitions, find the one in which the winter period is as short as possible. (It is quite cold now; there is really no reason for winter to be longer than necessary...) Write a function: def solution( T ) that, given a sequence T of temperature measurements (specified as integer numbers), finds the partition of the year into winter and summer that meets the conditions above and makes winter as short as possible, then retums the length of the winter. Both winter and summer have to be at least one day long. For example, given: T=[5,2,3,8,6] the function should return 3 , as after partitioning the year into winter: [5,2,3] and summer: [8,6], each winter' s measurement is smaller than each summer' 5 temperature

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!