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: | Tetrazocine |
---|---|
Location: | Melbourne, VIC, Australia |
Users: | 6 |
Nodes: | 8 (0 / 8) |
Uptime: | 46:38:20 |
Calls: | 45 |
Files: | 21,492 |
Messages: | 63,526 |