뻘질문) 왜 파이썬 리스트는 push가 아니라 append를 쓰는 걸까요?

조회수 6958회

list.pop()이 이미 있으니까 생각해보면 list.append()가 아니라 list.push()라고 해야 맞지 않나요?

왜 list.append()로 쓰는지 궁금해졌어요! 왤까요?

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기

    파이썬 역사를 보면 알 수 있습니다.

    list.append는 1991년(파이썬 초기)에 고안된 반면, pop은 그 1997년에 고안됐기 때문입니다.

    파이썬 창시자인 Guido도 pop에는 push가 더 적절하다고 생각했지만 같은 일을 하는 메소드를 다르게 명명하는걸 원치 않았기 때문에 append가 계속 살아남습니다.

    To implement a stack, one would need to add a list.pop() primitive (and no, I'm not against this particular one on the basis of any principle). list.push() could be added for symmetry with list.pop() but I'm not a big fan of multiple names for the same operation -- sooner or later you're going to read code that uses the other one, so you need to learn both, which is more cognitive load.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)