I tried to get the index of the list using the enumerate function

Enumerate function that can be used when index is not assigned

When I was thinking about when the enumerate function could be used effectively, the following tasks were asked in competitive programming, so I thought it was a good place to use it.

problem

When data on student tests and absenteeism is given in order of student ID number, create a program that outputs the student ID number of students whose grades are above the passing score. Student ID numbers are given in order from 1. Student grades shall be the test scores minus the number of absences x 5 points.

Input value

N M a_1 b_1 a_2 b_2 a_3 b_3 …

N: Number of students M: Minimum passing score a_n: Test score b_n: Number of absences

Get index using enumerate function

There may be other good ways, but let's use the enumerate function to output the answer. You can use the enumerate function to get the list element and index at the same time in a for loop.

# man:Number of students, score:Minimum passing score
#First, get each numerical value from the input value by map.
man , score = map(int , input().split())

#Prepare an empty list
li = []

#Elements obtained by map to list(A pair with elements of score and absenteeism)In a loop
for i in range(man):
    li.append(list(map(int , input().split())))

#Index of the obtained list using the enumerate function(Student number)Get list elements at the same time
#Output index by branching by calculating the numerical value in the element
for num , scr in enumerate(li):
    if (scr[0] - scr[1]*5) >= score:
        print(num + 1)
    elif ((scr[0] - scr[1]*5) < score) and score == 0:
        print(num + 1)

Recommended Posts

I tried to get the index of the list using the enumerate function
I tried to get a list of AMI Names using Boto3
I tried to get the batting results of Hachinai using image processing
I measured 6 methods to get the index of the maximum value (minimum value) of the list
I tried to approximate the sin function using chainer
Try to get the function list of Python> os package
I tried to get the location information of Odakyu Bus
I tried to fight the Local Minimum of Goldstein-Price Function
I tried to approximate the sin function using chainer (re-challenge)
I want to get the name of the function / method being executed
I tried to get a database of horse racing using Pandas
I tried the pivot table function of pandas
I tried to touch the API of ebay
I tried to correct the keystone of the image
I tried using the image filter of OpenCV
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
I tried to transform the face image using sparse_image_warp of TensorFlow Addons
I tried to estimate the similarity of the question intent using gensim's Doc2Vec
I tried to get the authentication code of Qiita API with Python.
I tried to extract and illustrate the stage of the story using COTOHA
I tried to get the RSS of the top song of the iTunes store automatically
I tried to get the movie information of TMDb API with Python
I tried the common story of using Deep Learning to predict the Nikkei 225
Using COTOHA, I tried to follow the emotional course of Run, Melos!
I tried to predict the deterioration of the lithium ion battery using the Qore SDK
I tried to learn the sin function with chainer
I tried to notify the update of "Hamelin" using "Beautiful Soup" and "IFTTT"
[Python] I tried to judge the member image of the idol group using Keras
I tried to summarize the basic form of GPLVM
I tried to get an AMI using AWS Lambda
I tried using the API of the salmon data project
I tried to visualize the spacha information of VTuber
I tried to erase the negative part of Meros
[Python] I tried to get the type name as a string from the type function
[Python] I tried to get Json of squid ring 2
I tried to identify the language using CNN + Melspectogram
I tried to complement the knowledge graph using OpenKE
I tried to classify the voices of voice actors
I tried to compress the image using machine learning
I tried to summarize the string operations of Python
I tried to understand the learning function of neural networks carefully without using a machine learning library (first half).
I tried to get the information of the .aspx site that is paging using Selenium IDE as non-programming as possible.
I tried to predict the victory or defeat of the Premier League using the Qore SDK
I tried to notify the update of "Become a novelist" using "IFTTT" and "Become a novelist API"
Python practice 100 knocks I tried to visualize the decision tree of Chapter 5 using graphviz
I tried to extract the text in the image file using Tesseract of the OCR engine
I tried to find the entropy of the image with python
[Horse Racing] I tried to quantify the strength of racehorses
I tried to find the average of the sequence with TensorFlow
I tried refactoring the CNN model of TensorFlow using TF-Slim
I tried to simulate ad optimization using the bandit algorithm.
I tried to get Web information using "Requests" and "lxml"
I tried face recognition of the laughter problem using Keras.
I want to get the operation information of yahoo route
I made a function to check the model of DCGAN
I tried adding post-increment to CPython. List of all changes
[Python] I tried to visualize the follow relationship of Twitter
I tried to implement the mail sending function in Python
[TF] I tried to visualize the learning result using Tensorboard
I tried a little bit of the behavior of the zip function