Issue
The two setups using print(i, j)
and print(i)
return the same result. Are there cases when one
should be used over the other or is it correct to use them interchangeably?
desc = {'city': 'Monowi', 'state': 'Nebraska', 'county':'Boyd', 'pop': 1}
for i, j in desc.items():
print(i, j)
for i in desc.items():
print(i)
for i, j in desc.items():
print(i, j)[1]
for i in desc.items():
print(i)[1]
Solution
Both are different if remove parenthesis in print because you are using python 2X
desc = {'city': 'Monowi', 'state': 'Nebraska', 'county':'Boyd', 'pop': 1}
for i, j in desc.items():
print i, j
for i in desc.items():
print i
output
county Boyd
city Monowi
state Nebraska
pop 1
('county', 'Boyd')
('city', 'Monowi')
('state', 'Nebraska')
('pop', 1)
Answered By - Artier
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.