In this article, we are going to create a function which will return a list of tuples that consist of a particular hour and the highest traffic volume for that particular hour. The stat has been taken every 10 minutes in each hour. For example, at 4.00pm the total numbers of traffics that pass through a junction for every 10 minutes are as follows: [23, 22, 45, 66, 54, 33]. The traffic volume measurement in this example will begin at 4.00pm and end at 8.00pm. Below is the solution to this problem.

def traffic_count(array):

    # first we will create the traffic volume list for 4pm, 5pm, 6pm and 7pm within a big list 
    count = 0
    arr_stat = []
    while(count < 24):
        count += 6

    # then we will create the tuple which consists of time and the peak traffic at that hour
    max = 0
    arrs = &#91;&#93;
    time = 4
    for elem in arr_stat:
        for item in elem:
            if max < item : #find out the higest stat
                max = item
        arrs.append(((str(time) + ":00pm"), max))
        time += 1
        max = 0

    return arrs
<!-- /wp:html -->

<!-- wp:html -->

traffic_count([23,24,34,45,43,23,57,34,65,12,19,45, 54,65,54,43,89,48,42,55,22,69,23,93]) # if you enter the above data into the function then you will get below outcome!
list of tuples consist of time vs traffic volume

Give your thought regarding this solution in the comment box below this post!

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *