a = []
len(a) # 0 출력
len([1, 2, 3]) # 3 출력
a = [1,2,3]
a.append(4) # a= [1,2,3,4]
a = [1,2,3]
a.insert(0,5) # a = [5,1,2,3]
a = [1,2,3]
a.pop() # 3 return
a = [1,2,3]
a.clear() # a=[]
a = [1, 2, 3]
2 in a #True
5 in a # False
5 not in a # True
def max_n(a):
n = len(a)
max_v = a[0]
for i in range(1, n):
if a[i] > max_v:
max_v = a[i]
return max_v
max_n(a) : 비교 연산 n-1번 수행 ==> O(n)
def find_max_index(a):
n = len(a)
max_idx = 0
for i in range(1, n):
if a[i] > a[max_idx]:
max_idx = i
return i
a[최댓값의 위치번호] = 최댓값
def min_n(a):
n = len(a)
min_v = a[0]
for i in range(1, n):
if a[i] < min_v:
min_v = a[i]
return min_v