Programming Languages/Python 16

[Python] 파이썬 index 함수 - 리스트에서 원하는 값의 인덱스 찾기

index 함수 파이썬에서 리스트 관련 함수들은 활용도가 높으니 항상 암기하고 있는 게 좋다. 여기서 리스트 관련 모든 함수들을 확인할 수 있다. 정확한 개념 및 사용 방법은 파이썬 공식 문서에서 확인 가능하다. 파이썬 공식 문서를 보면 index 관련 내용은 다음이 전부이다. array.index(x[, start[, stop]]) Return the smallest i such that i is the index of the first occurrence of x in the array. The optional arguments start and stop can be specified to search for x within a subsection of the array. Raise ValueErro..

[Python] 파이썬 join 함수 - 리스트를 하나의 문자열로 합쳐주는 함수

리스트의 요소들을 하나의 문자열로 합쳐주는 함수! 1. ''.join(리스트) 2. '구분자'.join(리스트) ''.join(리스트) # 매개변수 리스트에 있는 요소 하나하나를 합쳐서 하나의 문자열로 바꿔줌 '구분자'.join(리스트) # 구분자를 기준으로 리스트의 요소와 요소 사이에 '구분자'에 들어온 구분자를 넣어서 하나의 문자열로 합쳐줌 3. 코드 작성 예시 프로그래머스 > 문자열 내림차순으로 배치하기 def solution(s): return ''.join(sorted(s, reverse=True)) print(solution("안녕하세요")) # 하요안세녕 print(solution("123456789")) # 987654321 def solution2(s): return '.'.join(so..

반응형