# Create Dictionary
loc_mapping = {val : index for index, val in enumerate(strings)} # It doesn't mean val = index, but it means to express it in the form of val : index.
loc_mapping
When you run , you get the following result values:
{'a': 0, 'as': 1, 'bat': 2, 'car': 3, 'dove': 4, 'python': 5}
So I've just converted the code above that I've been compiling into a for statement.
for index, val in enumerate(strings):
loc_mapping = {val:index} #val = index does not mean, but it means to express it in the form of val:index
print(loc_mapping)
{'a': 0}
{'as': 1}
{'bat': 2}
{'car': 3}
{'dove': 4}
{'python': 5}
This is the result.
Like the result of the first code, I want to put all of it in one dictionary of
I'd appreciate it if you could tell me how to do it!
python for
loc_mapping = dict()
for index, val in enumerate(strings):
loc_mapping[val] = index #val = index, but it means to express it in the form of val: index.
print(loc_mapping)
589 PHP ssh2_scp_send fails to send files as intended
646 Uncaught (inpromise) Error on Electron: An object could not be cloned
579 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
583 Who developed the "avformat-59.dll" that comes with FFmpeg?
636 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.