"일꾼이 일을 잘하려면 먼저 도구를 갈고 닦아야 한다." - 공자, 『논어』.
첫 장 > 프로그램 작성 > Python 인터뷰 질문 - 초급부터 고급까지

Python 인터뷰 질문 - 초급부터 고급까지

2024-09-02에 게시됨
검색:265

Python Interview Question - Beginner to Advance

1. 면접관: 아래와 같이 출력을 얻기 위해 Python 코드를 작성합니다.

시간: 15분

레벨: 초급

예:

Input = "AAAABBBCCDAABBB"
Output= A4B3C2D1A2B3

가능한 답변

# define a function() that takes string input and return null if string is null and returns 1st occurrences of character followed by number of occurrences and so on. 

# This function takes a string and returns processed string output. 
def str_skimmer(input_string):
    # Return null string if input is null. 
    if not input_string:
        return ""
    # Store values for 2 parameters - "Reference Character and "Count"
    prev_char=input_string[0]
    op=[]
    count=1

    for i in input_string[1:]:
        if (i==prev_char):
            count  = 1 
            print(i, count, op)
        else: 
            op.append(prev_char str(count))
            prev_char=i
            count=1
    op.append(prev_char str(count))  
    print(op)

    return ''.join(op)
#O: A4B3C2D1A2B3

ip="AAAABBBCCDAABBB"
op= str_skimmer(ip)
print(op)

2. 면접관: 미정

시간: 15분

레벨: 초급

예:

Input = "TBD"
Output= TBD
릴리스 선언문 이 글은 https://dev.to/jasper475/python-interview-question-beginner-to-advance-1omp?1에서 복제됩니다. 침해 내용이 있는 경우, [email protected]으로 연락하여 삭제하시기 바랍니다.
최신 튜토리얼 더>

부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.

Copyright© 2022 湘ICP备2022001581号-3