-
문자열의 정렬Python/개념학습 2022. 11. 5. 16:01
a = ['cd', 'ef', 'ab'] a.sort() print(a) # ['ab', 'cd', 'ef']
문자열 자체를 정렬할 경우
s = "adcb" s1 = s.sort() # error s2 = sorted(s) # ['a','b','c','d'] s3 = ''.join(sorted(s)) # "abcd"
파이썬에서 str type은 sort메소드가 없음. sorted(문자열)의 형태로는 가능(이 때 리턴타입은 list)
'Python > 개념학습' 카테고리의 다른 글
순열(permutations)과 조합(combinations) (0) 2022.11.04 list 원소의 중복 제거 (0) 2022.10.27 map함수 활용 (0) 2022.10.27 Meaning of stack[-1][0] (0) 2022.08.24 collections 모듈 - extend, append (0) 2022.08.21