How to append all status codes to one list?

I want to add each error status in a list and after that visualize them with matplotlib or something else. The problem is that when I try to this it creates a separate list for each 404 code for example. How can I append all 404 errors in one list?

I want to be like this:

error_codes = ['404', '404, '404, ...]

My code:

import re

with open('./access_tail.txt', 'r') as f:
    data = f.readlines()

for line in data:
    pattern = re.compile(r'^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*((?:[01]\d|2[0-3]):(?:[0-5]\d):(?:[0-5]\d)).*((?:200|3[0][0-4]|4[0][0-4]|5[0][0-7]))')

    for (ip, date, status) in re.findall(pattern, line):
        print(ip, status, date)

    list = []
    if '404' in status:
        list.append(status)
        print(list)

My output:

193.27.228.27 404 10:24:03
['404']
189.39.247.86 403 11:04:06
193.27.228.27 404 11:29:47
['404']
117.222.59.231 403 13:23:47
123.234.86.215 404 13:57:15
['404']
23.98.152.191 404 14:05:23
['404']
23.98.152.191 404 14:05:23
['404']
23.98.152.191 404 14:05:24
['404']
23.98.152.191 404 14:19:11
['404']
193.118.53.202 403 14:36:41


Read more here: https://stackoverflow.com/questions/64410318/how-to-append-all-status-codes-to-one-list

Content Attribution

This content was originally published by Iman Ashoori at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: