[Python] A program that finds the most common bird types

[Python] A program that finds the most common bird types

This is a memo for myself.

▼ Question

--Enter the bird type numbers (positive integers) that passed in front of you in order in the list. --Returns the most witnessed bird species. --However, if multiple types are witnessed the same number of times, the number of the smallest type is returned.


▼sample input


arr = [1,1,1,4,4,4,5,3]

▼sample output



▼my answer


def migratoryBirds(arr):

    #Count the number of each type number
    for i in set(arr):
        if x<arr.count(i):
     #If the number of sightings is the same, give priority to the smaller type number
        elif x==arr.count(i):
            if minType>i:
    return minType

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')
    arr_count = int(input().strip())
    arr = list(map(int, input().rstrip().split()))
    result = migratoryBirds(arr)
    fptr.write(str(result) + '\n')

** ・ sightings ** Witness (animal) Its id number will be added to your array of sightings.

You would like to be able to find out which type of bird is most common given a list of sightings.

Recommended Posts

[Python] A program that finds the most common bird types
[Python] A program that rounds the score
[Python] A program that compares the positions of kangaroos.
[Python] A program that finds the minimum and maximum values without using methods
[Python] A program that finds the shortest number of steps in a game that crosses clouds
[Ev3dev] Create a program that captures the LCD (screen) using python
[Python] A program that rotates the contents of the list to the left
[Python] A program that creates stairs with #
A program that plays rock-paper-scissors using Python
[Python] A program that calculates the number of chocolate segments that meet the conditions
[Python] A program that finds a pair that can be divided by a specified value
[Python] A program that calculates the number of socks to be paired
[Python] Note: A self-made function that finds the area of the normal distribution
A program that removes duplicate statements in Python
A program that searches for the same image
A shell program that displays the Fibonacci sequence
[Python] A program that calculates the number of updates of the highest and lowest records
A story that struggled with the common set HTTP_PROXY = ~
Python program that looks for the same file name
A memo that I touched the Datastore with python
A Python program that converts ical data into text
A program that summarizes the transaction history csv data of SBI SECURITIES stocks [Python3]
There is a pattern that the program did not stop when using Python threading
A note that runs an external program in Python and parses the resulting line
A Python program in "A book that gently teaches difficult programming"
A general-purpose program that formats Linux command strings in python
A program that removes specific characters from the entered text
Write a python program to find the editing distance [python] [Levenshtein distance]
A program that automatically resizes the iOS app icon to the required image size in Python
I tried "a program that removes duplicate statements in Python"
[Python] A program that creates a two-dimensional array by combining integers
A Python program that aggregates time usage from icalendar data
[Golang] A program that determines the turn with random numbers
A Python script that compares the contents of two directories
[Python] A program to find the number of apples and oranges that can be harvested
Understand the probabilities and statistics that can be used for progress management with a python program
[Python] I tried to make a simple program that works on the command line using argparse.
Play a sound in Python assuming that the keyboard is a piano keyboard
I made a program that solves the spot the difference in seconds
A story that struggled to handle the Python package of PocketSphinx
From a book that programmers can learn (Python): Find the mode
A function that measures the processing time of a method in python
Read a file in Python with a relative path from the program
A program that determines whether a number entered in Python is a prime number
[Python algorithm] A program that outputs Sudoku answers from a depth-first search
A script that returns 0, 1 attached to the first Python prime number
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
Create a compatibility judgment program with the random module of python.
[Python] Make the function a lambda function
When writing a program in Python
The story of writing a program
Extract lines that match the conditions from a text file with python
A program that will slowly recover the economy from any news headline
Enum types that enter the standard library from Python 3.4 are still useful
A python program that resizes a video and turns it into an image
The eval () function that calculates a string as an expression in python
I made a program to check the size of a file in Python
From a book that makes the programmer's way of thinking interesting (Python)