[Code Wars] Greek Sort

문제

https://www.codewars.com/kata/56bc1acf66a2abc891000561/solutions

나의 풀이

다른 사람의 풀이

  1. Best Practice 1등의 풀이

    def greek_comparator(lhs, rhs):
        return greek_alphabet.index(lhs) - greek_alphabet.index(rhs)
    
    • greek_alphabet을 사용해야하는 것을 문제에서 제대로 명시 안해줬는데.. 답을 보고 좀 짜증이 났다
    • 하지만, 위와 같은 접근법은 생각을 못했는데 좋은 접근 법을 배울 수 있었다.
  2. 그외 풀이

    def greek_comparator(lhs, rhs):
        return cmp(greek_alphabet.index(lhs), greek_alphabet.index(rhs))
    
    • cmp 라는 built-in 모듈을 사용한다.
    • C 에서 strcmp 같은 역할을 하는 것 같은데, 아쉽게도 python3 버젼에서는 사라졌고, 위 Best practice 방법이 가장 적절한 것 같다.

회고