I was overwhelmed that three gurus inspire me in three different ways in their
own flavour:-) That's really appreciated! Now I understand why it's so, thanks
to all of you.
To Peter:
> With that information, can you predict what
> for k, v in {(1, 2): "three"}: print(k, v)
> will print?
On Thu, 28 Apr 2016 06:27 pm, jf...@ms4.hinet.net wrote:
> I have a dictionary like this:
>
dct ={1: 'D', 5: 'A', 2: 'B', 3: 'B', 4: 'E'}
>
> The following code works:
>
for k in dct: print(k, dct[k])
> ...
> 1 D
> 2 B
> 3 B
> 4 E
> 5 A
When you iterate over the dictionary, you get
jf...@ms4.hinet.net wrote:
> I have a dictionary like this:
>
dct ={1: 'D', 5: 'A', 2: 'B', 3: 'B', 4: 'E'}
>
> The following code works:
> But...this one?
>
for k,v in dct: print(k,v)
> ...
> Traceback (most recent call last):
> File "", line 1, in
> TypeError: 'int' object is
On Thursday, April 28, 2016 at 1:57:40 PM UTC+5:30, jf...@ms4.hinet.net wrote:
> I have a dictionary like this:
>
> >>> dct ={1: 'D', 5: 'A', 2: 'B', 3: 'B', 4: 'E'}
>
> The following code works:
>
> >>> for k in dct: print(k, dct[k])
> ...
> 1 D
> 2 B
> 3 B
> 4 E
> 5 A
>
> and this one too:
>
I have a dictionary like this:
>>> dct ={1: 'D', 5: 'A', 2: 'B', 3: 'B', 4: 'E'}
The following code works:
>>> for k in dct: print(k, dct[k])
...
1 D
2 B
3 B
4 E
5 A
and this one too:
>>> for k,v in dct.items(): print(k,v)
...
1 D
2 B
3 B
4 E
5 A
But...this one?
>>> for k,v in dct: