python iter on a dic key value

Solutions on MaxInterview for python iter on a dic key value by the best coders in the world

showing results for - "python iter on a dic key value"
Raheem
09 Jul 2019
1for k, v in d.items():
2    print(k, v)
3# key1 1
4# key2 2
5# key3 3
6
Bradford
20 Feb 2019
1items = d.items()
2print(items)
3print(type(items))
4# dict_items([('key1', 1), ('key2', 2), ('key3', 3)])
5# <class 'dict_items'>
6
7i_list = list(d.items())
8print(i_list)
9print(type(i_list))
10# [('key1', 1), ('key2', 2), ('key3', 3)]
11# <class 'list'>
12
13print(i_list[0])
14print(type(i_list[0]))
15# ('key1', 1)
16# <class 'tuple'>
17