- 2
a={ 1:'a', 2:'b', 3:'c'} for i,j in a.items(): print(i,j,end="#")
Please tell
2 Answers
0
What to tell??
It has indentation errorđ
Click tab on line 3rd line (before print)
0
Sampada Sharma
a={ 1:'a', 2:'b', 3:'c'}
First of all you are creating a dictionary with three keys with three values and you are storing it in a variable a(to be specific you are making variable 'a' to reference the dictionary)
for i,j in a.items():
Now you are traversing the dictionary
'i' --> stores all the keys
'j' --> stores all the values
as .items function(method) returns the data like this
([(1, 'a'), (2, 'b'), (3, 'c')]) ( to be specific dict_items([(1, 'a'), (2, 'b'), (3, 'c')]))
print(i,j,end="#")
now we are printing the result . As we have used end = '#' . Every new line starts with #
Your overall code should look like this
a={ 1:'a', 2:'b', 3:'c'}
for i,j in a.items():
print(i,j,end="#")
output:
1 a#2 b#3 c#
ă
€ă
€ă
€ this is what he is asking for