Hello All,
How to get keys and values both form dict?
For eg. i want "(u'option2', True): 3" for res.
res = {(False, True): 1, (u'option2', True): 3, (u'option1', True): 2}
Thanks in advance
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hello All,
How to get keys and values both form dict?
For eg. i want "(u'option2', True): 3" for res.
res = {(False, True): 1, (u'option2', True): 3, (u'option1', True): 2}
Thanks in advance
Hi,
refer this:
https://stackoverflow.com/questions/8023306/get-key-by-value-in-dictionary
Accept answer if helpful..
Thank you.
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
2
thg 11 22
|
12493 | ||
|
0
thg 3 21
|
24 | ||
|
1
thg 1 18
|
15522 | ||
|
1
thg 2 25
|
1076 | ||
|
0
thg 11 23
|
1325 |
Hi Pawan,
You need to use iteritems.
res = {(False, True): 1, (u'option2', True): 3, (u'option1', True): 2}
for key,value in res.iteritems():
print key, value
output:
(False, True) 1
(u'option2', True) 3
(u'option1', True) 2
Hope it helps,
Regards,
Mayank Gosai
If you want to use for python 3.
You have to use res.items() instead of res.iteritems().
For ex:
res = {(False, True): 1, (u'option2', True): 3, (u'option1', True): 2}
for key,value in res.items():
(print (key,value))
Output:
(False, True) 1
('option2', True) 3
('option1', True) 2
Thanks,
Mayank Gosai