5
방금 Racket에 pattern matching 기능이 있습니다. 매우 강력합니다.파이썬에서 패턴 매칭 기능이 있나요?
> (match '(1 2 3) [(list a b c) (list c b a)])
'(3 2 1)
> (match '(1 2 3) [(list 1 a ...) a])
'(2 3)
> (match '(1 2 3)
[(list 1 a ..3) a]
[_ 'else])
'else
> (match '(1 2 3 4)
[(list 1 a ..3) a]
[_ 'else])
'(2 3 4)
> (match '(1 2 3 4 5)
[(list 1 a ..3 5) a]
[_ 'else])
'(2 3 4)
> (match '(1 (2) (2) (2) 5)
[(list 1 (list a) ..3 5) a]
[_ 'else])
'(2 2 2)
파이썬에서 비슷한 구문 설탕이나 라이브러리가 있습니까?