char_rdic = list('helo')
char_dic = {w:i for i ,w in enumerate(char_rdic)}
I'm not really sure what this code actually do. what does w and i represent in this code?
char_rdic = list('helo')
char_dic = {w:i for i ,w in enumerate(char_rdic)}
I'm not really sure what this code actually do. what does w and i represent in this code?
This is a dict comprehension. If you are familiar with list comprehension ([do_stuff(a) for a in iterable]
construct), that works very much the same way, but it builds a dict.
See Create a dictionary with list comprehension in Python and https://docs.python.org/3.5/tutorial/datastructures.html#dictionaries for the official documentation
This code creates char_dic
dictionary with chars from 'helo'
string as keys and their occurence indexes in given string.
i
is an index of w
element in char_rdic
list.