from datetime import datetime


def timestamp2dt(strings,delimiter='-',reverse=False):
    """Parse a list of strings into python datetime instances. Format of
    dates can be yyyy-mm-dd 00:00:00.0000 or dd-mm-yyyy 00:00:00.0000. 
    
    Parameters
    ----------
    strings: list
        Each list entry is a string which defines the date. The format of
        the string is flexible. 
    delimiter: string, optional
        Default == "-" (dash). Character which seperates the date numbers. 
    reverse: bool, optional
        if format is dd-mm-yyyy set reverse = True
    
    Returns
    ----------
    serial_num: list
        Each entry in list is python datetime instance. 
    """
    #go through each date string and convert to datetime, doesnt deal with american times
    dates = [datetime.now()] * len(strings)
    yr_idx = 0 # index of the year in string 
    dy_idx = 2 # index of the day in string 
    if reverse:
        yr_idx = 2
        dy_idx = 0 # nb: month should always be 1
        
    for i in range(len(strings)):
        entry = strings[i].split()
        temp = entry[0].split(delimiter)
        time = entry[1].split(':')
        try:
            second = time[2].split('.')[0] # not always possible to get seconds 
        except:
            second = 0 
        dates[i] = datetime(int(temp[yr_idx]),
                             int(temp[1]),
                             int(temp[dy_idx]),
                             int(time[0]),
                             int(time[1]),
                             int(second))
    return dates