popitem() 의 사용에 대해서
동영상 강의에 오류가 있는거 같습니다.
dict_a.popitem() 을 제가 실행했을 때는
몇 번이나 계속 실행해봐도
해당 dict 의 가장 마지막요소를 반환하는데
영상에서는 "임의의 요소"를 반환한다고 하셨네요
제가 제대로 이해하고 있는게 맞는지 궁금합니다.
답변 3
4
The popitem() method removes the item that was last inserted into the dictionary. In versions before 3.7, the popitem() method removes a random item. The removed item is the return value of the popitem() method, as a tuple, see example below.
Remove and return a (key, value) pair from the dictionary. Pairs are returned in LIFO order.
popitem() is useful to destructively iterate over a dictionary, as often used in set algorithms. If the dictionary is empty, calling popitem() raises a KeyError.
Changed in version 3.7: LIFO order is now guaranteed. In prior versions, popitem() would return an arbitrary key/value pair.
버전별로 동작이 상이 하기 때문에 외국 포럼에서도 질문이 자주 등장합니다.
https://stackoverflow.com/questions/4809044/removing-items-randomly-from-a-dictionary
감사합니다.
인스턴스 변수 문의
0
29
1
챕터 03_04 (튜플) 교육자료
0
28
2
Package(3-1) Sub 폴더 자료
0
35
1
아톰 출력 안됨
0
61
2
강의자료 메일 발송 요청 드립니다.
0
71
1
강의자료 메일로 보내주실 수 있으실까요?
1
48
0
Iterable 요소는 리스트로 작성해야하는 것 맞나요?
1
73
2
강의자료 부탁드립니다
0
57
2
if Flase: print('Bad')
0
57
1
=와 == 의 차이
0
74
1
functions 함수 섭들을려고하는데요
0
66
1
강의자료 부타드리겠습니다!
0
57
0
VSCODE에 VIEW에서 SELECTED INTERPRETER조회가 안됩니다.
0
65
1
강의자료 부탁드립니다.
0
50
0
dict의 Key를 바꾸는 방법
0
61
1
강의자료부탁드립니다
0
59
1
run withount 디버깅 및 F5+ctrl이 안먹혀요
0
59
1
강의 자료와 예정 다운로드
0
72
2
객체지향 vs 함수형
0
56
1
어렵네요 설정도
0
69
1
설정이 잘 된건지
0
50
1
맥 os vscode 설정 - python interpreter select
0
99
1
강의자료 부탁드립니다. mytoughgirl@naver.com 입니다.
0
43
1
vscode로 수업 진행한 영상은 없는건가요?
0
55
2





