Items() và iteritems() dùng để làm gì?

dict.items(): return a copy of the dictionary’s list of (key, value) pairs.

dict.iteritems(): return an iterator over the dictionary’s (key, value) pairs.

Mình không hiểu iterator nghĩa là cái gì, cho nên không hiểu luôn ý nghĩa của hai cái hàm trên…
Thêm nữa là hàm set, ví dụ:

eg = { 'a': 1, 'b': 2 }
eg_set = set(eg.iteritems())

Mình thấy cái iterator giống kiểu “bố” của mấy thằng string, list, dict, tuple,… :smile:

http://zetcode.com/lang/python/itergener/
http://www.tutorialspoint.com/python/dictionary_items.htm
http://www.dotnetperls.com/dictionary-python

Khác biệt giữa 2 cái đó :smile:

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?