Giter Site home page Giter Site logo

Comments (4)

HxH2H avatar HxH2H commented on July 27, 2024 3

제가 답글을 남기는게 조금 주제 넘을 수도 있지만 제가 아는 선에서 말씀을 드리자면 해당 오류는 자료형이 맞지 않거나 함수 호출 규약을 틀렸을 경우에 나타나는 오류로 알고 있습니다. 예를 들어 s = ["h","e","l","l","o"] 이런식의 문자 배열 형태를 가지고 있어야 s[:] = s[::-1] 와 같은 슬라이싱이 가능하다고 생각합니다.

제가 글쓴분의 전체적인 코드를 알 수 없어 정확하게 답변은 불가능 하지만 간단하게 예시를 들자면,
s = "hello"
위와 같은 경우에는 s[0] 또는 s[1] 그리고 s[1:3] 과 같은 슬라이싱은 가능하지만 s[:] = s[::-1] 와 같은 문자열 변경은 불가능합니다.
위와 같은 형식으로 코드를 사용하셨다면 s = s[::-1] 로 하시면 오류없이 실행이 됩니다.

s = ["h","e","l","l","o"]
s[:] = s[::-1]
이런 경우처럼 입력값을 문자 배열로 사용하셨다면 가능합니다.
부족한 설명 들어주셔서 감사합니다.
(죄송합니다 저의 설명에 오류가 있어 수정 하였습니다.)

from python-algorithm-interview.

hwangjeongwoo avatar hwangjeongwoo commented on July 27, 2024 1

네, 답변 감사합니다.

말씀하신 것처럼 저는 문자열에 대한 슬라이싱인 줄 알았는데,
지금 책을 다시 보니 다음 문구를 제대로 못봤네요.
"만약 입력값이 문자열이라면 앞서 살펴본 바와 같이 문자열 슬라이싱을 사용할 수 있다.
슬라이싱은 리스트에도 사용할 수 있으며, 성능 또한 매우 좋다.
s = s[ : :-1]"

from python-algorithm-interview.

likejazz avatar likejazz commented on July 27, 2024

@legendhangkali 답변 감사드립니다.
말씀하신대로 책 p146에서 sList입니다. 그래서 s[:] = s[::-1]가 가능하지만 아마 @hwangjeongwoo 님이 작성하신 코드에서는 sstr로 선언한 것으로 보입니다. str은 불변 객체(immutable object, p110 참고)로 변수내의 값을 조작할 수 없습니다. s = s[::-1] 이런 형태로 완전한 재할당만 가능합니다.

감사합니다.

from python-algorithm-interview.

hwangjeongwoo avatar hwangjeongwoo commented on July 27, 2024

네, 확인 감사드립니다!!

from python-algorithm-interview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.