If a dictionary key has a Python list as its value, you can read the values one by one in the list using a for-loop like in the following.
d = {k: [1,2,3]}
for v in d[k]:
print(v)
No tutorial describes this, why?
What is the Python explanation for this behaviour?
If a dictionary key has a Python list as its value, you can read the values one by one in the list using a for-loop like in the following.
d = {k: [1,2,3]}
for v in d[k]:
print(v)
No tutorial describes this, why?
What is the Python explanation for this behaviour?
<class 'list'>d = {'key': [1, 2, 3]}
type(d['key'])
<class 'list'>val = d['key']
type(val)
... print(v)for v in val:
If a dictionary key has a Python list as its value, you can read the values >one by one in the list using a for-loop like in the following.
d = {k: [1,2,3]}
for v in d[k]:No tutorial describes this, why?
print(v)
What is the Python explanation for this behaviour?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 452 |
Nodes: | 16 (4 / 12) |
Uptime: | 04:13:48 |
Calls: | 9,278 |
Calls today: | 11 |
Files: | 13,511 |
Messages: | 6,070,739 |
Posted today: | 2 |