When using dict as an iterator in a for statement, there are times when you want to use both key and value. Also index when list is used as a lata.
I'll write it down every time, so I'll write it down.
By the way, I used to do this ↓
python3
>>> dict = {'a': 10, 'b': 20, 'c': 30}
>>> for key in dict.keys():
>>> print('key: ', key, ' ,value: ', dict[key])
key: a ,value: 10
key: b ,value: 20
key: c ,value: 30
It seems that if you make two variables after for and pass dict.items (), key and value will be entered in each.
python3
>>> dict = {'a': 10, 'b': 20, 'c': 30}
>>> for key, value in dict.items():
>>> print('key: ', key, ' ,value: ', value)
key: a ,value: 10
key: b ,value: 20
key: c ,value: 30
Use enumerate (list) if you want to use index and value in list
python3
>>> l = ['a', 'b', 'c']
>>> for index, value in enumerate(l):
>>> print('index: ', index, ' ,value: ', value)
index: 0 ,value: a
index: 1 ,value: b
index: 2 ,value: c
You can do the same with pandas Series and DataFrame, but the value set in index will not be applied and index = 0,1,2, ...
By the way, in the map of js, the same thing is written in a split assignment.