Generating random numbers as the value of dictionary in python
<p>Could you please tell me how can I generate a dictionary with 100 rows that have random number between 0 and 1 in each row as the value? For example in data frame, I can have:</p>

<pre><code>   df['Rand'] = random.sample(random.random(), 100)
</code></pre>

<p>But I don't know how to do that for a dictionary.</p>

<p>Firstly, it should be <code>list</code> and not <code>dict</code>. Check: <a href="http://stackoverflow.com/questions/3489071/in-python-when-to-use-a-dictionary-list-or-set">In Python, when to use a Dictionary, List or Set?</a></p>

<p>In order to get the list of values, you may use <em>list comprehension</em> as: </p>

<pre><code>&gt;&gt;&gt; import random
&gt;&gt;&gt; row_count = 10
&gt;&gt;&gt; my_list = [random.random() for i in range(row_count)]
# Value of 'my_list':
# [0.9158936600374181, 0.8998648755500501, 0.07002867165493243, 0.6694284854833131, 0.4903966580363698, 0.9462143737260301, 0.8014661448602305, 0.47964245438139297, 0.42326131297319725, 0.77540761767324]
</code></pre>

<p>In order to fetch 5th item (i.e. 4th index):</p>

<pre><code>&gt;&gt;&gt; my_list[4]
0.4903966580363698
</code></pre>

python dictionary random