깊은 복사2 ❗️[LEET CODE] 46. Permutations ( 객체 복사 ) # Problem Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. Constraints: 1 List[List[int]]: return list(itertools.permutations(nums)) itertools 모듈의 permutations 함수는 튜플 모음을 반환 # 객체 복사 파이썬에서는 모든 것이 객체이기 때문에 '=' 를 이용하면 객체의 참조가 복사되기 때문에 원래의 값을 변경하면 참조한 값도 변경된다. 리스트의 경우 a[:], a.copy() 를 이용하면 값을 복사한 다른 객체를 생성 복잡한 리스트의 경우 a.copy.deep.. 2021. 4. 7. [코딩 + 알고리즘 완주반] 11일차. Object Reference # is , __eq__ is, id : id 비교 ( 같은 객체 인지) __eq__, == : 값이 같은지 비교 # 객체 참조 중요한 특징들 # python object reference print("ex1-1") print(dir()) # id vs __eq__ (== 증명) x = {'name':'kim','age':33,'city':'Seoul'} y=x # 얕은 복사 print('ex-2-1 - ', id(x),id(y)) print('ex-2-2 - ', x==y) print('ex-2-3 - ', x is y) print('ex-2-4 - ', x,y) x['class'] = 10 # x가 수정되면 y도 수정됨 print('ex2-5 - ',x,y) print() z = {'name':'ki.. 2021. 3. 25. 이전 1 다음 반응형