[Python] A program that calculates the number of updates of the highest and lowest records

This is a memo for myself.

▼ Question

--The score (positive integer) for each match order is stored in the list. --Using the first score as a reference value, calculate the number of times the highest score was updated and the number of times the lowest score was updated.

URL

▼sample input

python


scores =[3,4,21,36,10,28,35,5,24,42]

▼sample output

python


4 0

▼my answer

python


def breakingRecords(scores):
    high=low=scores[0]
    xhigh=xlow=0
    
    for i in scores:
        if i>high:
            xhigh+=1
            high=i
        elif i<low:
            xlow+=1
            low=i
    ans = [xhigh, xlow]
    return ans

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')
    n = int(input())
    scores = list(map(int, input().rstrip().split()))
    result = breakingRecords(scores)
    fptr.write(' '.join(map(str, result)))
    fptr.write('\n')
    fptr.close()

** ・ tabulate ** Make a table. She tabulates the number of times she breaks her season record.

Recommended Posts

[Python] A program that calculates the number of updates of the highest and lowest records
[Python] A program that calculates the number of chocolate segments that meet the conditions
[Python] A program that calculates the number of socks to be paired
[Python] A program that counts the number of valleys
[Python] A program to find the number of apples and oranges that can be harvested
[Python] A program that compares the positions of kangaroos.
[Python] A program that finds the shortest number of steps in a game that crosses clouds
[Python] A program that rounds the score
[Python] A program that rotates the contents of the list to the left
[Python] A program that finds the maximum number of toys that can be purchased with your money
A discussion of the strengths and weaknesses of Python
[Python] A program that finds the minimum and maximum values without using methods
[Python] A program that calculates the difference between the total numbers on the diagonal line.
A python script that gets the number of jobs for a specified condition from indeed.com
A program that summarizes the transaction history csv data of SBI SECURITIES stocks [Python3]
A note that runs an external program in Python and parses the resulting line
A program that just presses and releases the Esc key
[Python] A program that finds the most common bird types
A Python script that compares the contents of two directories
A server that returns the number of people in front of the camera with bottle.py and OpenCV
A library that monitors the life and death of other machines by pinging from Python
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
The story of Python and the story of NaN
This and that of python properties
The story of writing a program
Count the number of Thai and Arabic characters well in Python
A formula that simply calculates the age from the date of birth
A story that struggled to handle the Python package of PocketSphinx
Probability of getting the highest and lowest turnip prices in Atsumori
A function that measures the processing time of a method in python
[Ev3dev] Create a program that captures the LCD (screen) using python
Try to write a program that abuses the program and sends 100 emails
A program that determines whether a number entered in Python is a prime number
A script that returns 0, 1 attached to the first Python prime number
Verification of the theory that "Python and Swift are quite similar"
A program that answers a few questions and predicts the next answer
I made a program that automatically calculates the zodiac with tkinter
[python] A note that started to understand the behavior of matplotlib.pyplot
The story of making a module that skips mail with python
Get the number of readers of a treatise on Mendeley in Python
Create a compatibility judgment program with the random module of python.
A program that receives the servo command of the radio control, interrupts the Raspberry Pi and logs it
Understand the probabilities and statistics that can be used for progress management with a python program
[Python] A program that compares each element of list one by one and wins or loses. zip ()
[Python] A program that creates stairs with #
I made a calendar that automatically updates the distribution schedule of Vtuber
This and that of the inclusion notation.
[Python / Jupyter] Translate the comment of the program copied to the clipboard and insert it in a new cell
Calculate the shortest route of a graph with Dijkstra's algorithm and Python
Get the number of searches with a regular expression. SeleniumBasic VBA Python
Check the in-memory bytes of a floating point number float in Python
Connect a lot of Python or and and
A python program that resizes a video and turns it into an image
Use AWS lambda to scrape the news and notify LINE of updates on a regular basis [python]
Get the number of articles accessed and likes with Qiita API + Python
The eval () function that calculates a string as an expression in python
Set the process name of the Python program
The story of blackjack A processing (python)
I made a program to check the size of a file in Python
A program that plays rock-paper-scissors using Python
From a book that makes the programmer's way of thinking interesting (Python)