250x250
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 |
Tags
- stop the world
- python list method
- 객체지향
- 알고리즘
- 심볼릭 레퍼런스
- 코딩테스트
- 플랫폼 클래스 로더
- 클래스 로더 계층
- getreference
- 스프링
- 자바
- AWS SAA-C03 합격후기
- 파이썬 리스트 메서드
- 스프링 컨테이너
- 다이렉트 레퍼런스
- Spring
- 파이썬
- BFS
- 어플리케이션 클래스 로더
- 딕셔너리
- dfs
- 파이썬 문자열 메서드
- 컴포넌트 스캔
- 자료구조
- 부트스트랩 클래스 로더
- python
- java
- aws saa-c03
- 2026 AWS SAA-C03
- 백준
Archives
- Today
- Total
클라우드 낚시꾼
[Python] 파이썬(Python) 유용한 리스트(list) 메서드 모음 본문
Programming Language/Python 활용
[Python] 파이썬(Python) 유용한 리스트(list) 메서드 모음
KanuBang 2024. 9. 16. 15:32728x90
append
list의 마지막에 요소 삽입
my_list=[1,2,3]
my_list.append(4)
print(my_list)
extend
list의 마지막에 iterable 객체(list, tuple 등등)의 모든 요소들을 삽입
my_list=[1,2,3]
my_list.extend((4,5))
print(my_list)
insert
list의 특정 index에 요소를 삽입
my_list=[1,2,3]
my_list.insert(1,10)
print(my_list)
remove
파리미터로 전달된 요소를 list에서 찾아 삭제, 첫 번째로 찾아진 요소가 삭제된다.
my_list=[1,2,3,2]
my_list.remove(2)
print(my_list)
pop
- list의 마지막 요소를 삭제하고, 그 요소를 리턴
my_list=[1,2,3]
popped_item = my_list.pop()
print(popped_item)
print(my_list)
- 파리미터로 전달받은 인덱스에 위치한 요소를 list에서 삭제하고, 그 요소를 리턴
my_list=[1,2,3]
popped_item = my_list.pop(1)
print(popped_item)
print(my_list)
count
파리미터로 전달된 요소가 리스트에 몇개 있는 지 세고 그 값을 반환한다.
my_list=[1,2,3,2]
cnt = my_list.count(2)
print(cnt)
sort
- 리스트를 정렬한다. (오름차순 정렬이 default)
my_list=[3,1,2]
my_list.sort()
print(my_list)
- sort의 reverse에 True를 전달하면 내림차순 정렬을 할 수 있다.
my_list=[3,1,2]
my_list.sort(reverse=True)
print(my_list)
reverse
리스트를 거꾸로 뒤집는다.
my_list=[1,2,3]
my_list.reverse()
print(my_list)
copy
리스트를 얕은 복사하여 반환한다. 이 메서드로 복사된 리스트는 원본 리스트와 독립적이다.
my_list=[1,2,3]
new_list = my_list.copy()
new_list[0] = 100
print(my_list, new_list)
my_list=[1,2,3]
print(my_list)
list
iterable 객체(string, tuple, set 등등)을 리스트로 만들어 반환한다.
hello = list("hello")
print(hello)
set = list({1,2,3})
print(set)728x90
'Programming Language > Python 활용' 카테고리의 다른 글
| [Python] 파이썬(Python) 유용한 문자열(String) 메서드 모음 (0) | 2024.09.14 |
|---|---|
| [Python] 파이썬(Python) 딕셔너리(해시 테이블) 관련 함수, 메서드 모음 (1) | 2024.09.12 |
| [Python3] 딕셔너리 정렬하기 with lambda (0) | 2024.03.20 |
| [Python3] Python 출력문 정리 (0) | 2024.03.15 |
| [Python3] Python 대소문자 관리 (upper, lower) (0) | 2024.03.15 |