python strange looking loop
<pre><code>      char_rdic = list('helo')
      char_dic = {w:i for i ,w in enumerate(char_rdic)}
</code></pre>

<p>I'm not really sure what this code actually do. what does w and i represent  in this code?  </p>

<p>This is a dict comprehension. If you are familiar with list comprehension (<code>[do_stuff(a) for a in iterable]</code> construct), that works very much the same way, but it builds a dict.</p>

<p>See <a href="https://stackoverflow.com/questions/1747817/create-a-dictionary-with-list-comprehension-in-python">Create a dictionary with list comprehension in Python</a>
and <a href="https://docs.python.org/3.5/tutorial/datastructures.html#dictionaries" rel="nofollow">https://docs.python.org/3.5/tutorial/datastructures.html#dictionaries</a> for the official documentation</p>

python