Iterate over Python list and convert Python date to human readable string
<p>I have a python list that stores IP addresses, hostnames and dates.</p>

<p>I need to iterate over this list and convert the python dates to human readable dates.</p>

<p>How can I iterate over the list and convert the dates to human readable strings?</p>

<p>List:</p>

<pre><code>{'_id': '192.168.1.5', '192.168.1.5', 'u_updated_timestamp': datetime.datetime(2016, 9, 1, 20, 27, 38, 364000), 'u_hostname': 'test.example.com'}, {'_id': '192.168.1.3', 'u_ipv4': '192.168.1.3', 'u_updated_timestamp': datetime.datetime(2016, 9, 2, 9, 40, 5, 347000), 'u_hostname': test.test.com}, {'_id': '192.168.1.8', 'u_ipv4': '192.168.1.8', 'u_updated_timestamp': datetime.datetime(2016, 9, 2, 13, 13, 5, 403000), 'u_hostname': hosttest.example.com}
</code></pre>

<p>Simply iterate by the list and modify / add datetime to human-readable:</p>

<pre><code>for row_id, row in enumerate(your_list):
    your_list[row_id]['human_readable_date'] = row['u_updated_timestamp'].strftime("specify-your-format")
</code></pre>

<p>You can find datetime formats <a href="https://docs.python.org/2/library/datetime.html" rel="nofollow">here</a>.</p>

python