개발
리스트(List)
jih0ssang
2023. 11. 26. 15:06
리스트
remove()
list = [0, 1, 2, 3]
list.remove(3) # index 3 삭제
replace()
a = "23"
a = a.replace('2', '3') # 2 -> 3
리스트를 [], 없이 출력
“”.join(array)
값 대입
scores = [[1, 2], [4, 6], [0, 6]]
a, b = scores[0] # a=1, b=2
for a, b in scores:
# a= scores의 x, b= scores의 y
원하는 데이터의 index 알아내기
- index() : 숫자 등
- find() : 문자열. list 내 문자열.find() 가능
배열 2개 동시에 비교(집합)
a = [1,3,2,5,4]
for p1, p2 in zip(a, a[1:]):
print(p1, p2)
# 1 3
# 3 2
# 2 5
# 5 4
중복값 찾기
X = [1, 2, 3, 4], Y = [3, 4, 5]
Duplicate_value = set(X)&set(Y) # [3, 4]