Engineering Note

if문 하나 if_else 문으로 가독성 증가 본문

Programming Language/Clean_Code

if문 하나 if_else 문으로 가독성 증가

Software Engineer Kim 2021. 10. 30. 23:58

수정 전

import sys
from collections import deque

input = sys.stdin.readline

testcase = int(input())

for _ in range(testcase):
    number_of_docs, target = map(int,input().split())
    docs = list(map(int,input().split()))

    print_q = deque()

    for index, value in enumerate(docs):
        print_q.append((index,value))

    cnt = 1

    while print_q:
        front_doc = print_q.popleft()

        for cur_doc in print_q:
            if cur_doc[1] > front_doc[1]:
                print_q.append(front_doc)
                break
        else:
            if front_doc[0] == target:
                print(cnt)
                break
            else:
                cnt += 1

수정 후

import sys
from collections import deque

sys.stdin = open("input.txt")

input = sys.stdin.readline

testcase = int(input())

for _ in range(testcase):
    number_of_docs, target = map(int,input().split())
    docs = list(map(int,input().split()))

    print_q = deque()

    for index, value in enumerate(docs):
        print_q.append((index,value))

    cnt = 1

    while print_q:
        front_doc = print_q.popleft()

        for document in print_q:
            if front_doc[1] >= document[1]:
                continue
            else:
                print_q.append(front_doc)
                break
        else:
            if front_doc[0] == target:
                print(cnt)
                break
            else:
                cnt += 1
Comments