for v in d[k]:
print(v)
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: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 919 |
Nodes: | 10 (1 / 9) |
Uptime: | 73:48:45 |
Calls: | 12,186 |
Calls today: | 1 |
Files: | 186,526 |
Messages: | 2,236,786 |